This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Are private base classes really private ?


David C Binderman <dcb@pncl.co.uk> writes:

> struct A { };
> struct B : private A {};

> B b;
> A* pa = (A *) &b; // should fail here, according to 15.3.2 of Stroustrup 3.

Not according to the Standard.  It says [expr.cast]:

7 In addition to those conversions, the following static_cast and  rein-
  terpret_cast  operations  (optionally  followed by a const_cast opera-
  tion) may be performed using the cast notation of explicit  type  con-
  version, even if the base class type is not accessible:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  --a pointer to an object of derived class type or an lvalue of derived
    class type may be explicitly converted to a pointer or reference  to
    an unambiguous base class type, respectively;
[snip]

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]