This is the mail archive of the gcc@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: c++ virtual base classes


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


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