C++ Constructor and Destructor

Constructor and Destructor

The derived class destructor is called first, and then the base class destructor gets called.
The base class constructor is called first.


inheriting classes, the base class' constructor and destructor are not inherited.

Lets create a sample class that includes a constructor and a destructor

we can define constructor and a destructor for the ''Sister'' class.
Sister ::Sister() {
 cout << "constructor" << endl;
Sister::~Sister () {
 cout << "destructor" << endl;

You can think of it as the following: The derived class needs its base class in order to work - that is why the base class is set up first.