#include <iostream>
using namespace std;
class Parent
{
public:
Parent (int a)
{
this->a = a;
cout << "Parent 构造函数被调用" << endl;
}
public:
int a;
};
class Parent1 :public Parent
{
public:
Parent1 (int b):Parent(1)
{
this->b = b;
cout << "Parent1 构造函数被调用" << endl;
}
void print1()
{
printf ("b = %d\n", b);
}
public:
int b;
};
class Parent2 :public Parent
{
public:
Parent2 (int b) :Parent(3)
{
this->d = b;
cout << "Parent2 构造函数被调用" << endl;
}
void print2()
{
printf ("d = %d\n", d);
}
public:
int d;
};
class C:public Parent1, public Parent2
{
public:
C(int e):Parent1(2), Parent2(4)
{
this->e = e;
cout << "C 构造函数被调用" << endl;
}
void printc()
{
printf ("e = %d\n", e);
}
private:
int e;
};
int main()
{
C c(10);
c.Parent1::a = 10;
return 0;
}
多继承的二义性 钻石结构
最新推荐文章于 2020-08-05 19:41:30 发布