virtual Constructors/Destructors
3 posters
Page 1 of 1
virtual Constructors/Destructors
Can we have a virtual constructor ? a virtual destructor?
if yes ,why? and if not,why?
if yes ,why? and if not,why?
alok jha- Posts : 2
Join date : 2009-01-30
Re: virtual Constructors/Destructors
suppose A is the base class,b the derived class.
A *bptr = new B;
Virtual destructor:
becomes helpful to clear up the space allocated to bptr.
NOTE: without virtual destructor it would not be possible to clear up properly the elements that only belong to B.
Virtual constructor
is redundant because any way the 'new B' will call both B's constructor and A's constructor.
A *bptr = new B;
Virtual destructor:
becomes helpful to clear up the space allocated to bptr.
NOTE: without virtual destructor it would not be possible to clear up properly the elements that only belong to B.
Virtual constructor
is redundant because any way the 'new B' will call both B's constructor and A's constructor.
ramthegreatcv- Posts : 55
Join date : 2009-01-30
Age : 36
Re: virtual Constructors/Destructors
there can't be any virtual constructor.because when obect is being created then object doesn't know the classes derivered from it so it can;t call any derived function
mnnit.rahul- Posts : 51
Join date : 2009-02-01
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|