问题
填空题
请在mian函数中填空使下面程序的输出结果为1 1。
#include<iostream.h>
class A
private:
int a;
int b;
public:
A( ):a(0) ,b(1)
void show( ) cout < < a < < " " < < b; ;
class B
private:
int a;
int c;
public:
B( ):a(1),c(1)
void show( ) cout < < a <
< " " < < c; ;
class C:public A,public B
;
void main( )
C cc;
【12】
答案
参考答案:【12】cc.B::show( );
解析:【命题目的】关于C++中用加域名解决二义性的方法。
【解题要点】class A中有show( )函数,class B中也有show( )函数,class C继承了 class A和class B,产生二义性,这时C的对象cc必须用域名来确定调用的是哪个show函数,因为答案是1 1,所以要加域名B::。
【考点链接】C++中二义性的解决方法。