Computer Science 1037A/B Lecture 34: Constructors, Destructors and Inheritance
Document Summary
By inheriting every member of the base class, a derived class object contains a base class object. The derived class constructor can specify which base class constructor should be used to initialize the base class object. When an object of a derived class is created, the base class"s constructor is executed first, followed by the derived class"s constructor. When an object of a derived class is destroyed, its destructor is called first, then that of the base class. This program demonstrates the order in which base and derived class constructors and destructors are called. { cout << "this is the basedemo constructor. \n"; } { cout << "this is the basedemo destructor. \n"; } //derived class class deridemo : public basedemo public: deridemo() //constructor. { cout << "this is the deridemo constructor. \n"; } { cout << "this is the deridemo destructor. \n"; } int main() cout << "we will now create a deridemo object. \n";