mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

virtual Constructors/Destructors

3 posters

Go down

virtual Constructors/Destructors Empty virtual Constructors/Destructors

Post  alok jha Wed Feb 04, 2009 9:43 pm

Can we have a virtual constructor ? a virtual destructor?
if yes ,why? and if not,why?

alok jha

Posts : 2
Join date : 2009-01-30

Back to top Go down

virtual Constructors/Destructors Empty Re: virtual Constructors/Destructors

Post  ramthegreatcv Mon Feb 16, 2009 1:37 pm

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.
ramthegreatcv
ramthegreatcv

Posts : 55
Join date : 2009-01-30
Age : 36

Back to top Go down

virtual Constructors/Destructors Empty Re: virtual Constructors/Destructors

Post  mnnit.rahul Sun Mar 01, 2009 7:09 pm

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

Back to top Go down

virtual Constructors/Destructors Empty Re: virtual Constructors/Destructors

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum