子类的构造和析构过程, 上代码:
#include
using namespace std; class CA { public: CA() { cout << "CA()" << endl; } ~CA() { cout << "~CA()" << endl; } }; class CB : public CA { public: CB() { cout << "CB()" << endl; } ~CB() { cout << "~CB()" << endl; } }; int main() { cout << "Hello, World!" << endl; CB b; return 0; }
输出:
总结:
孙子类的构造和析构过程, 上代码:
#include
using namespace std; class CA { public: CA() { cout << "CA()" << endl; } ~CA() { cout << "~CA()" << endl; } }; class CB : public CA { public: CB() { cout << "CB()" << endl; } ~CB() { cout << "~CB()" << endl; } }; class CC : public CB { public: CC() { cout << "CC()" << endl; } ~CC() { cout << "~CC()" << endl; } }; int main() { cout << "Hello, World!" << endl; //CB b; CC c; return 0; }
输出:
总结:
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/223281.html原文链接:https://javaforall.net
