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