#include<iostream>
using namespace std;
class object
{
public:
object(int a=0, int b=0)
{
this->a = a;
this->b = b;
cout << "我是祖宗构造函数"<<a<<b<< endl;
}
~object()
{
cout << "我是祖宗析构函数"<< endl;
}
private:
int a;
int b;
};
class parent : public object
{
public:
parent(int c) :object(1,2 )
{
this->c = c;
cout << "我是爸爸构造"<< endl;
}
~parent()
{
cout << "我是爸爸析构"<< endl;
}
protected:
int c;
private:
};
class child :public parent
{
public:
child(int d) :parent(1) ,o1(3, 4), o2(5,6)
{
this->d = d;
cout << "我是儿子构造"<< endl;
}
~child()
{
cout << "我是儿子析构"<< endl;
}
private:
int d;
object o1;
object o2;
};
void objplay()
{
child c1(1);
}
void main()
{
objplay();
system("pause");
}
C++ 继承和组合混搭下的构造与析构
最新推荐文章于 2022-08-19 14:23:56 发布