试题与答案

在下面横线上填上适当的语句,完成程序。 #include <iostream> us

题型:填空题

题目:

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

答案:

参考答案:Derived(int i):Base(i){}

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

试题推荐
题型:补全对话,情景问答
看图,完成句子。
1. — What are they doing?  
    — They are                           
2. — What is she doing?   
    — She is                             
                           3.  — What is he doing?
     —                                                                                                                      
4. — What's he doing?
    —                            
5. — What's he doing?
    —                            
查看答案
微信公众账号搜索答案