问答题
#include < iostream.h >
class Base
{ public:
Base ( int x, int y)
{a=x; b=y;}
virtual void Show() { cout << " Base:" << a << "," << b; }
private:
int a, b;
};
class Derived:public Base
{ public:
Derived(int x, int y, int z):Sase(x, y), c(z) {}
void Show() { Base::Show(); cout << " Derived:" << c << endl; }
private:
int c;
};
void main()
{ Base b(10,20);
Base * ref = &b;
Derived d(30,60,90);
ref-> Show();
cout << endl;
ref = &d;
ref - > Show ();
【参考答案】
Base:10,20
Base:30,60 Derived:90