 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dave Moore Guest
|
Posted: Sat Jan 15, 2005 3:23 am Post subject: private virtual inheritance |
|
|
Recent discussions here:
http://groups-beta.google.com/group/comp.lang.c++.moderated/msg/f837c18868c56616
and in comp.std.c++:
http://groups-beta.google.com/group/comp.std.c++/msg/3f6fda6a03cb5c6a
have gotten me thinking about virtual private inheritance, I found the
following example in an older thread of a canonical class hierarchy using
private virtual inheritance:
class I { /* something */ };
class A : private virtual I { /* implement half of I */ };
class B : private virtual I { /* implement another half of I */ };
class C : public A, public B { /* something */ };
First of all, how *should* this be handled by a Standard conforming
compiler? The Standard says (12.6.2 /6) that only the most derived class is
responsible for instantiating class I, however class I is not an accessible
base class of C, so its constructors cannot be called from C. I messed
around with some examples in g++, and it was clear that its implementation
treats ctors of private virtual base classes "exceptionally", exposing them
to derived classes further down the class hierarchy
A more general question is, doesn't this mean that the Standard should
require that base classes inherited privately and virtually have no
user-defined ctors?
Actually, is virtual private inheritance useful for anything? I searched
this NG and comp.std.c++ and I couldn't find any *convincing* examples.
Thanks,
Dave Moore
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
David Bradley Guest
|
Posted: Mon Jan 24, 2005 11:29 am Post subject: Re: private virtual inheritance |
|
|
Dave Moore wrote:
| Quote: | Actually, is virtual private inheritance useful for anything? I searched
this NG and comp.std.c++ and I couldn't find any *convincing* examples.
|
The example you stated is more complex than what I normally find useful
for virtual private functions.
Normally the pattern I encounter is where I want the derived classes to
implement an interface. That interface is used by the base class
implementation in satifying it's requirements. This private interface
allows me to specify what my derived classes must implement. This
interface is an implementation detail and not part of the public
interface to the base class. The benefit of this is that it allows me to
provide common logic around the private interface without duplicating
that for each and every derived class.
I'm probably not doing this justice in my description here, but
hopefully you see the point.
David Bradley
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|