#include <iostream>
using namespace std;
class gradfather
{
public:
//gradfather(){}
gradfather(int i)
{
a=i;
cout<<"构造基类a的值:"<<a<<endl;
}
~gradfather(){cout<<"析构基类a的值"<<endl;}
private:
int a;
};
class father
{
public:
//father(){}
father(int j)
{
b=j;
cout<<"构造子类b的值"<<b<<endl;
}
~father(){cout<<"析构子类b的值"<<endl;}
private:
int b;
};
class son : public gradfather,public father
{
private:
int c;
public:
son(int k,int m,int n);
~son(){cout<<"析构子类c的值"<<endl;}
};
son::son(int k,int m,int n):father(m),gradfather(n)
{
c=k;
cout<<"构造子类c的值:"<<c<<endl;
}
int main()
{
son(1,2,3);
return 0;
}
子类传递参数到多个基类构造函数
最新推荐文章于 2023-10-22 05:06:13 发布