在下面横线上填上适当的语句,完成程序。 #include<iostream> using namespace std; class Base { int x; public: Base(int i){

admin2009-02-15  25

问题 在下面横线上填上适当的语句,完成程序。
   #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的构造函数应该包括调用基类构造函数使基类的数据成员得以初始化。
转载请注明原文地址:https://kaotiyun.com/show/WOkp777K
0

随机试题
最新回复(0)