选择题
为完成下面的程序,在画线处应填入的语句是______。
#included<iostream>
using namespace std;
class Base
{
int x;
public:
Base(int i){x=i;}
~Base(){}
};
class Derived:public Base
{
public:
______//完成类Derived构造函数的定义
};
int main()
{
Derived obj(2);
return 0;
}
A、
Derived(int i):Base(i){}
B、
Derived(){}
C、
vold Derived(in*i):Base(i){}
D、
Derived(int i){Base(i);}
【正确答案】
A
【答案解析】
在派生类的构造函数中,必须对基类的成员进行初始化,并且必须在构造函数的初始化列表中调用基类的构造函数。
提交答案
关闭