本文主要是介绍C++中class继承构造函数和析构函数的执行顺序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
如下示例:
class base{
private:int i;
public:base(int x){i = x;cout << "base structor function" << endl;}~base(){cout << "the class base destructor is called i = " << i << endl;}virtual void print(){cout << "the class base print" << endl;}
};class test1:public base
{
private:int k;
public:test1(int y, int z):base(y){k = z;cout << "test1 structor function" << endl;}~test1(){cout << "the class test1 destructor is called k = " << k << endl;}void print(){cout << "the class test1 print" << endl;}
};int main(int argc, char *argv[])
{test1 *pobj = new test1(5, 6);cout << endl;delete pobj;while (1);return 0;
}
这篇关于C++中class继承构造函数和析构函数的执行顺序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!