# 填空：间接基类就是A

#include <iostream>
using namespace std;
class A
{
protected:
int x;
public:
A(int a)
{
x=a;
}
};

//***************begin*****************
class B: ___(1)_____ A
{
protected:
int y;
public:
B(int a,int b):A(a)
{
y=b;
}
};

class C:___(2)_____A
{
protected:
int z;
public:
C(int a,int b):A(a)
{
z=b;
}
};

class D: _________(3)__________
{
private:
int t;
public:
D(int a, int b, int c, int d):_________(4)___________{}
void output()________(5)_________
};
//***************end*****************
void D::output()
{
cout<<"x from A: "<<x<<endl;
cout<<"y from B: "<<y<<endl;
cout<<"z from C: "<<z<<endl;
cout<<"t from D: "<<t<<endl;
}

int main( )
{
int a, b, c, d;
cin>>a>>b>>c>>d;
D x(a,b,c,d);
x.output();
return 0;
}

4个整数，将在D类对象的构造函数中，分别初始化来自几个类中的数据成员

``1 2 3 4``

``````x from A: 1
y from B: 2
z from C: 3
t from D: 4``````

``````#include<stdio.h>
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("x from A: %d\n",a);
printf("y from B: %d\n",b);
printf("z from C: %d\n",c);
printf("t from D: %d\n",d);
return 0;
}``````

``````
#include <iostream>
using namespace std;
class A
{
protected:
int x;
public:
A(int a)
{
x=a;
}
};
class B:virtual public A
{
protected:
int y;
public:
B(int a,int b):A(a)
{
y=b;
}
};

class C:virtual public A
{
protected:
int z;
public:
C(int a,int b):A(a)
{
z=b;
}
};

class D: public B, public C
{
private:
int t;
public:
D(int a, int b, int c, int d):A(a), B(a, b), C(a, c), t(d) {}
void output();
};
void D::output()
{
cout<<"x from A: "<<x<<endl;
cout<<"y from B: "<<y<<endl;
cout<<"z from C: "<<z<<endl;
cout<<"t from D: "<<t<<endl;
}

//main函数
int main( )
{
int a, b, c, d;
cin>>a>>b>>c>>d;
D x(a,b,c,d);
x.output();
return 0;
}``````