问题 填空题

使用VC6打开考生文件夹下的工程test25_1,此工程包含一个源程序文件test25_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
privatel from derived1:30
privatel from derived2:30
源程序文件test25_1.cpp清单如下:
/***************found******************/
include<iostream.h>
class base

protected:
int privatel;
public:
base(int p)privatel=p;
;
/****************found*******************/
class derived1:public base

public:
derivedl(int p1):base(p1);
int get_private()return private1;

class derived2:virtua1 public base

public:
derived2(int p2):base(p2);
int get_private()return private1;
;
class derived12:public derived1,public derived2

public:
/****************found*******************/
derived12(int p1,int p2,int pb):derived1(p1), base(pb), derived2(p2);
;
void main()

derived12 d(10,20,30);
cout<<"privatel from derived1:"<<d.derived1::get_private();
cout<<"\nprivatel from derived2:"<<d.derived2::get_private();
cout<<endl;

答案

参考答案:
(A)错误:include<iostream.h>
正确:#include<iostream.h>
(B)错误:class derivedl:public base
正确:class derivedl:virtual public base
(C)错误:derivedAB(int pA,int pB,int pb):derivedl(pA),base(pb),derivedB(pB){};
正确:derivedAB(int pA,int PB,int Pb):derivedl(PA),derivedB(pB),base(Pb){};

解析:
(1)主要考查考生对于include关键字的掌握,它的正确使用是#include;
(2)主要考查考生对于虚基类的使用,为了正确的显示结果,这里应该使用虚基类的定义,这样在调用函数的时候就可以不产生二义性;
(3)主要考查考生对于初始化参数表中赋值顺序的掌握,它是按照从右至左依次赋值的。

选择题
单项选择题