问题 填空题

有如下程序:
#include<iostream>
using namespace std;
class Base
int b;
public:
Base(int i)b=i;
void disp( )cout<<"Base:b="<<b<<’’;

class Basel:virtual public Base
public:
Basel(int i):Base(i)
f;
class Base2:virtual public Base
public:
Base2(int i):Base(i)

class Derived:public Base2.public Basel
int d;
public:
Derived(inl i,int j):Basel(j),Base2(J),______d=i;
void disp( )cout<<"Derived:d="<<d<<":
f;
int main( )
Derived objD(1,2);objD.disp( );
objD.Basce::disp( );
objD.Bascel::disp( );
objD.Basce2::disp( );
return 0;
请将程序补充完整,使程序在运行时输出:
Derived:d=1 Base:b:2 Base:b=2 Base:b=2

答案

参考答案:Base(j)

解析: 派生类构造函数对基类构造函数的初始化,如果基类的构造函数带参,则必须在派生类构造函数中对其进行初始化。

多项选择题
选择题