This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c++ virtual base classes
- To: scherrey at proteus-tech dot com
- Subject: Re: c++ virtual base classes
- From: flatmax <flatmax at cse dot unsw dot EDU dot AU>
- Date: Thu, 8 Jul 1999 16:04:48 +1000 (EST)
- cc: egcs at egcs dot cygnus dot com
Yep - but there is no :
static class VBase{};
decleration allowed !!
Which means it can't be inherited and must be a static variable ... not
really the best and perhaps overlooked by the specs. ?
On Thu, 8 Jul 1999, Benjamin Scherrey wrote:
> That's once per instance I believe not once globally as you would get
> by using a static member (which is what I believe you really want). If
> you had a multiple inheritance situation where VBase would be
> inherited more than once, using virtual inheritance would ensure that
> its ctor/dtor was called only once for that object instance, otherwise
> it would be called as many times as it appeared in the inheritance
> hierarchy and you would have multiple copies of its data members.
>
> later,
>
> Ben Scherrey
>
> flatmax wrote:
> >
> > Hi,
> >
> > I thought virtual base classes were only ment to be initialised once ?
> > Check the following (attatched as a file - just comile it and run it):
> >
> > #include <iomanip.h>
> > class VBase {
> > public: VBase(){cout <<"init "<<this<<endl;}
> > };
> > class topLevel : virtual public VBase {
> > public: topLevel(){cout <<"topLevel init "<<this<<endl;}
> > };
> >
> > Then if I do the following :
> >
> > main (){
> > topLevel _1, _2;
> > }
> >
> > The ouput is like so :
> > init 0xbffff4f4
> > topLevel init 0xbffff4f0
> > init 0xbffff4ec
> > topLevel init 0xbffff4e8
>
Matt
__________
reverse ...
backwards needs forwards
want backwards - first go forwards
viva