填空题
根据给定的程序执行结果,将下列程序补充完整。
#include
class Base{
public:
Base(int i) {b=i;}
(1)
protected: int b; };
class Derive1:public Base{
public:
(2)
void Print(){
cout<<"Derive1's Print() called."<Print();
}
void main( ){
(5)
1(6) 2
fun(d1);
fun(d2);
}
程序的执行结果如下:
Derive1's Print() called.
Derive2's Print() called.
【正确答案】
1、virtual void Print(){} // void virtual Print(){ } Derive1(int i=0):Base(i){} Derive2(int i=0):Base(i){} cout<<"Derive2's Print() called."<
【答案解析】