#include using namespace std;

class AA { public: AA() { cout << 'Constructor of AA is called.' << endl; } virtual void fn() { cout << 'AA function is called.' << endl; } };

class BE : public AA { public: BE() { cout << 'Constructor of BB is called.' << endl; } void fun() { cout << 'BB function is called.' << endl; } };

int main() { BE b; b.fn(); b.fun(); return 0; }

C++ 代码优化:继承和多态实例

原文地址: https://www.cveoy.top/t/topic/j9Ym 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录