C ++ Primer Plus learning note-taking class initialization sequence base class constructor, destructor and operator functions operator = cannot be inherited by the derived class; then, when creating a derived class object, how do I call the base class constructor to initialize the base class data ??? The answer is: when executing the constructor, follow the sequence of First Brother (base class), then guest (Object member), and then self (derived class). On the other hand, when executing the destructor, first, execute the destructor of the derived class, and then execute the destructor of the base class. The reason is that the destruction of the base class implies the destruction of the derived class, so the destructor of the derived class must be executed first;
# Include
Using namespace std; class Member {public: Member () {cout <"Member created" <
运行结果:
Base created
Member created
Derived created
Derived destroyed
Member destroyed
Base destroyed