问题 填空题

在下面的程序的横线处填上适当的语句,使该程序的输出结果为12。
#include<iostream>
using namespace std;
class TestClass

public:
int a,b;
TestClass(int i,int j)

a=i;
b=j;

;
class TestClass1:public TestClass

int a;
public:
TestClass1(int x):TestClass(x,x+1)
void show()

______;∥输出基类数据成员a的值
cout<<b<<endl;

;
int main()

TestClass1 d(1);
d.show();
return 0;

答案

参考答案:cout<<TestClass∷a

解析: 题目中程序TestClass为基类,TestClass1为派生类,在主函数中定义TestClass1对象d(1)。据题目要求“输出基类数据成员a的值”,基类为TestClass,利用∷域运算符取其成员a的值。

单项选择题
单项选择题