C++ 代码优化:继承和多态实例
#include
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; }
原文地址: https://www.cveoy.top/t/topic/j9Ym 著作权归作者所有。请勿转载和采集!