填空题
如下程序执行后的输出结果是{{U}} 【14】 {{/U}}。
#include <iostream>
using namespace std;
class Base
{
public:
Base(int x,int y)
{
a=x;
b=y;
}
void Show()
{
cout<<"Base: "<<a<< ',' <<b<<" ";
}
private:
int a,b;
};
class Derived : public Base
{
public:
Derived(int x, int y, int z) : Base(x,y),c(z) { }
void Show()
{
cout<<"Derived:"<<c<<end1;
}
private:
int c;
};
int main()
{
Base b(100,100),*pb;
Derived d(10,20,30);
pb=&b;
pb->Show();
pb=&d;
pb->Show();
return 0;
}
【正确答案】
1、Base:100,100 Base:10,20
【答案解析】[解析] 本题考核对象指针的应用。主函数中通过对象指针pb.分别调用其类成员函数Show()和派生类成员函数Show()先后输出 Base:100,100Base:10,20。