问题
填空题
若有以下程序:
#include<iostream>
using namespace std;
class Base
public:
void who()cout<<"Base"<<end1;
class Derived1:public Base
public:
void who()cout<<"Derived"<<end1;
;
int main()
Base *p;
Derived1 obj1;
p=&obj1;
p—>who();
return 0;
则该程序运行后的输出结果是 【9】
答案
参考答案:Derived
解析: 本题考核对象指针的使用。题中基类Base对象指针p用派生类Derived对象。obj1来初始化,那么通过对象指针p调用的who函数版本为基类Base中定义的版本,所以程序输出Derived。