Topic: Calling qualified member functions: a question


Author: claus@faerber.muc.de (Claus Faerber)
Date: 1995/12/21
Raw View
sanjayp@hpcll169.cup.hp.com (15 Dec 95):

>
> Hi nettors,
>
>   I would like to know if the following program is legal or not:
>   //------------------------------------------------------
>   class X {
>     ~X() { ... }
>   };
>
>
>   class A {
>     class X : public ::X {
>      ~X() { ... }
>     };
>     void foo() {
>       X o1;
>
>       o1.::X::~X();  // we want the dtor for the first X to
>                      // be called, how else to specify that?
>     }
>   };

You *can't* specify, which dtor is called first, if you called the ::X::~X
dtor first, then it would be called again in X::~X again!
And you can NEVER call a destructor explicitly!!

>   According to the April ANSI C++ draft the construct o1.::X::~X() seems
> illegal because
>
>    postfix-expression:
>               :
>    postfix-expression . id-expression
>
>   And id-expression cannot start with '::' .

What you're trying is to tell the compiler, that it should treat o1 as a ::X.
You can do this by:
        (::X)o1.method();

>    If that is the case, should the standard be modified to allow this
> kind of construct?

** NO! **

===========================================================================
 Claus Andre Faerber                                <claus@faerber.muc.de>
 Mitterfeldstrasse 20 * D-83043 Bad Aibling * Germany * fax: +49-8061-2057
===========================================================================
## CrossPoint v3.1 ##


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]