问题 单项选择题

为完成下面的程序,应在划线处填入的语句是 #include<iostream> using namespace std; class Base { private:int x; public:Base(int i){ x=i;}~Base(){} }; class Derived:public Base { public:______ //完成类Derive构造函数的定义 }; int main() {Derived obj;return 0; }

A.Derived(int :Base({}

B.Derived(){}

C.Void Derived (int :Base({}

D.Denved(int {Base(;}

答案

参考答案:A

解析: 本题考核派生类中的构造函数。程序中,类Derived是基类Base的公有派生。在类Derived的构造函数应该包括调用基类构造函数使基类的数据成员得以初始化。

单项选择题
单项选择题