标签:toc style csu 需要 new end code virt 注意
1. 虚函数中存在默认值时,需要注意其函数调用中默认值:
class cbase { public: virtual void func(int a = 10) { cout << "this is cbase func:" << a << endl; } }; class csub : public cbase { public: void func(int a = 20) { cout << "this is csub func:" << a << endl; } };
cbase * cbToCb = new cbase; cbase * cbTocSub = new csub; csub * cSubTocSub = new csub;
cbToCb->func(); // "this is csub func:10"
cbTocSub->func(); // "this is csub func:10"
cSubTocSub->func(); // "this is csub func:20"
标签:toc style csu 需要 new end code virt 注意
原文地址:https://www.cnblogs.com/weiyouqing/p/14664112.html