一起答
单选

带有虚基类的多层派生类构造函数的成员初始化列表中都要列出虚基类的构造函数,这样将对虚基类的子对象初始化(  )。

  • A.与虚基类下面的派生类个数有关
  • B.多次
  • C.两次
  • D.一次
参考答案
查看试卷详情
相关试题
  1. 使用VC6打开考生文件夹下的工程test8_1,此工程包含一个源程序文件test8_l.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:

     f1 function of derive

     f2 function of base

     f4 function of base

     源程序文件test8_1.cpp清单如下;

       #include<iostream.h>

        class base

       {

       public:

       /*********found**********/

        void f1(){cout<<"f1 function of base"<<endl;}

        virtual void f2(){cout<<"f2 function of base"<<endl;)

        virtual void f3(){cout<<"f3 function of base"<<endl;)

        void f4(){cout<<"f4 function of base"<<endl;)

       };

       /*******+*found**********/

       class derive::public base

       {

        void f1(){cout<<"f1 function of derive"<<endl;)

        void f2(int X){cout<<"f2 function of derive"<<endl;)

        void f4(){cout<<"f4 function of derive"<<endl;)

       };

       void main()

       {

        base *p;

        derive obj2;

       /******+**found**********/

        p=obj2;

        p->fl();

        p->f2();

        p->f4();

       }

  2. 使用VC6打开考生文件夹下的工程test11_3。此工程包含一个test11_3.cpp,其中定义了类CPosition,但该类的定义都并不完整。请按要求完成下列操作,将类CPosition的定义补充完整。

     (1)在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx,double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。请在注释“//**1**”之后添加适当的语句。

     (2)在类体中添加函数move(double ax,double ay)的定义,使得点的坐标x和y分别移动ax和ay个单位,请在注释“// **2**”之后添加适当的语句。

     (3)完成函数double distance (double bx,double by)的定义,该函数返回*this和点(bx,by)的距离,请在注释“//**3**”之后添加适当的语句。

     注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

     源程序文件test11_3.cpp清单如下:

     #include<iostream.h>

     #include<math.h>

     class CPosition

     {

     public:

       CPosition();

       CPosition(double dx,double dy);

       double getx();

       double gety();

         // ** 2 **

       double distance(double bx,double by);

     private:

       double x;

       double y;

     };

     // ** 1 **

     {

      x=0;y=0;

      }

     CPosition::CPosition(double dx,double dy)

     {

     x=dx;y=dy;

     }

     double CPosition::getx()

     {

     return x;

     }

     double CPosition::gety()

     {

     return y;

     }

     double CPosition::distance(double bx,double by)

     {

        // ** 3 **

     }

     void main()

     {

     double a,b;

     cout << "Input x, y position of a point:";

     cin >> a >> b;

     CPosition psA(a,b);

     cout << “Input x,y position of another point:";

     cin >> a >> b;

     cout << "The distance is " << psA.distance(a,b) <<endl;

     }

  3. 与所使用的计算机无关的是数据的

    • A.物理结构
    • B.逻辑结构
    • C.存储结构
    • D.逻辑和物理结构
  4. 若要把函数void f()定义为aClass的友元函数,则应该在类aClass的定义中加入的语句是(  )。

    • A.void f();
    • B.static voidf();
    • C.friend f();
    • D.friend void f();
  5. 下列重载函数中,正确的是(  )。

    • A.void fun(int a,float b);void fun(int c,float d)
    • B.void fun(int a,float b);void fun(float a,int b)
    • C.float fun(int a,float b);int fun(int b,float a)
    • D.int fun(int a,int b);float fun(int a,int b)
  6. 若在表达式y/x中,“/”是作为成员函数重载的运算符,则该表达式还可以表示为

    • A.x.operator/(y)
    • B.operator/(x,y)
    • C.y.operator/(x)
    • D.operator/(y,x)
  7. 执行语句for(i =1++<4;);,后变量i的值是

    • A.3
    • B.4
    • C.5
    • D.不定
  8. 语句int*P=&k;定义了指针P,与这个语句等效的语句序列是(   )。

    • A.int* p;P=&k;
    • B.int * P;P=k;
    • C.int * p;* P=&k;
    • D.int * p;* P=k;
  9. for(int x=0,y=0;!x&&y<=5;y++)语句执行循环的次数是

    • A.0
    • B.5
    • C.6
    • D.无数次
  10. 下列对字符数组进行初始化中,(  )是正确的。

    • A.char s1[]="abcd";
    • B.char s2[3]="xyz";
    • C.char s3[][]={"a","x", "y");
    • D.char s4 [2][3]={"xyz", "rnnp"};