Thread View: comp.std.c++
2 messages
2 total messages
Started by Igor Boukanov
Fri, 15 Mar 1996 00:33
Access to private base class?
Author: Igor Boukanov
Date: Fri, 15 Mar 1996 00:33
Date: Fri, 15 Mar 1996 00:33
23 lines
1508 bytes
1508 bytes
Here the lines from September DWP, 5.2.6.9:
[Example:
class A { virtual void f(); };
class B { virtual void g(); };
class D : public virtual A, private B {};
void g()
{
D d;
B* bp = (B*)&d; // cast needed to break protection
...
Does "cast needed to break protection" mean that in this case it is possible
to get access to the private base class by simple cast expression?
--
Regards, Igor Boukanov (igor.boukanov@fi.uib.no).
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: Access to private base class?
Author: Fergus Henderson
Date: Fri, 15 Mar 1996 02:03
Date: Fri, 15 Mar 1996 02:03
29 lines
1723 bytes
1723 bytes
boukanov@sentef1.fi.uib.no (Igor Boukanov) writes:
>Here the lines from September DWP, 5.2.6.9:
>
>class D : public virtual A, private B {};
>void g()
>{
> D d;
> B* bp = (B*)&d; // cast needed to break protection
>...
>
>Does "cast needed to break protection" mean that in this case it is possible
>to get access to the private base class by simple cast expression?
Yes.
From Stroustrup's book Design and Evolution of C++, page 328:
"The fact that an old-stype cast can be used to gain access to the part of a
representation that is a private base is an unfortunate historical accident."
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads