13年题。
This commit is contained in:
33
OOP/13Exam/2.1.cpp
Normal file
33
OOP/13Exam/2.1.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// 在下面基类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;
|
||||
};
|
||||
Reference in New Issue
Block a user