33 lines
557 B
C++
33 lines
557 B
C++
// 在下面基类Base和派生类Derived中增加成员函数show,使得程序运行结果如下:
|
||
// Base
|
||
// Derived
|
||
|
||
#include <iostream>
|
||
using namespace std;
|
||
class Base {
|
||
public:
|
||
// _________________________;
|
||
|
||
virtual void show() {
|
||
cout << "Base" << endl;
|
||
}
|
||
};
|
||
|
||
class Derived : public Base {
|
||
public:
|
||
// __________________________;
|
||
|
||
virtual void show() {
|
||
cout << "Derived" << endl;
|
||
}
|
||
};
|
||
|
||
int main() {
|
||
Base b, *ptr;
|
||
Derived d;
|
||
ptr = &b;
|
||
ptr->show();
|
||
ptr = &d;
|
||
ptr->show();
|
||
return 0;
|
||
}; |