[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [LC++]virtual functions



oh a big mistake. sorry. 
now look at the following:

code sample:

class base
{
virtual void print (void)
{
cout << "base"<<endl;
}
};

class derived : public base
{
void print (void)
{
cout << "derived" << endl;
}
};

int main (int argc, char argv)
{
derived d;

return 0;
}

now the ques. is whether virtual table will be
created?
how many?
one for base?
and one for derived?
there is no base class pointer scenario
even then virtual table will be created?
if yes why?

mehul.

 --- Torsten Rennett <Torsten@Rennett.de> wrote: 
> On Donnerstag, 28. Oktober 2004 10:17, choube mehul
> wrote:
> > when is the virtual table created?
> 
> When the object is created.
> 
> > will a virtual table created in the following
> > scenario?
> 
> For objects of class base a virtual table will be
> created, but not for 
> objects of class derived.
> 
> > if created why?
> 
> Because class base has a virtual method print().
> 
> > if not created why?
> 
> Because class derived has no virtual methods.
> (Note: class derived is not derived from any class.)
> 
> > class base
> > {
> > virtual void print (void)
> > {
> > cout << "base"<<endl;
> > }
> > };
> >
> > class derived
> > {
> > void print (void)
> > {
> > cout << "derived" << endl;
> > }
> > };
> >
> > int main (int argc, char argv)
> > {
> > derived d;
> >
> > return 0;
> > }
> 
> -- 
> Ingenieurbuero RENNETT      -- innovative
> Software-Entwicklung --
> Torsten Rennett                   
> http://www.RENNETT.de
> Ludwig-Thoma-Weg 14         E-Mail:           
> Torsten@Rennett.de
> D-85551 Heimstetten         Telefon:            +49
> 89 904 805 38
> 
> _______________________________________________
> This is the Linux C++ Programming List
> :
> http://lists.linux.org.au/listinfo/tuxcpprogramming
> List
>  

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony