Write a program to demonstrate the order of call of constructors and destructors in case of multiple inheritance where one or more base classes are virtual.
#include <iostream>
using namespace std;
class Base_A
{
public:
Base_A()
{
cout <<"First base class constructor"<<"\n";
}
~Base_A()
{
cout <<"First base class destructor"<<"\n";
}
};
class Base_B
{
public:
Base_B()
{
cout << "Second base class constructor\n";
}
~Base_B()
{
cout << "Second base class destructor\n";
}
};
class Derived : public Base_A, public Base_B
{
public:
Derived()
{
cout << "Derived class constructor" << "\n";
}
~Derived()
{
cout << "Derived class destructor" << "\n";
}
};
int main() {
cout<<"Order of call of constructors:\n\n";
Derived obj;
cout<<"\nOrder of call of destructors:\n\n";
return 0;
}
Output
Comments
Leave a comment