Files
2023-06-02 00:03:58 +08:00

33 lines
557 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 在下面基类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;
};