20 likes | 173 Views
Order of Execution of Constructors and Destructors in Inheritance. class base { protected: int d1; public: base() { cout <<" ctor base"<< endl ; } base( int a):d1(a) { cout <<" ctor overloaded base"<< endl ; } ~base() { cout <<" dtor base"<< endl ; } };.
E N D
Order of Execution of Constructors and Destructors in Inheritance
class base { protected: int d1; public: base() { cout<<"ctor base"<<endl; } base(int a):d1(a) { cout<<"ctor overloaded base"<<endl; } ~base() { cout<<"dtor base"<<endl; } }; class derive: public base{ protected: int d2; public: derive(): base(2) { cout<<"ctor derive"<<endl; } ~derive() { cout<<"dtor derive"<<endl; } };