C++ Virtual Destructors and Constructors

Asked By 0 points N/A Posted on -

I am seeking for information regarding C++ Virtual Destructors and Virtual Constructors.

And what is the need of Virtual Destructors without Virtual Constructors?

And what is the effect of having a Virtual Contractors in class constructor?

Can anyone send some information?

Thank you.

Answered By 0 points N/A #95340

C++ Virtual Destructors and Constructors


Hi Alvaradolucas,

Constructors and destructors are the special member functions of the classes that are used to construct and destroy class objects. Construction may involve memory initialization for objects. Destruction involve cleanup and de-allocation of memory for object. Like the other members function, constructors and destructors are declared with in a class declaration. Both can be define inline or external to the class declaration. Constructors can have default arguments. Unlike other member functions, constructors can have member initialization lists.

These following restrictions applied to constructors and destructors;

Constructors and destructors don’t have return types nor can they return value

Reference and pointers can’t be used on constructors and destructors because their addresses cannot be taken.

Constructors can’t be declared with the keyword virtual.

Constructors and destructors can’t be declared static,  const,  or  volatile.

Unions can’t contain class object that have constructors or destructors.



Best Regards,

George Marcus

Login/Register to Answer

Related Questions