class CBase
{
public:
virtual void Test(int iTest = 0) const = 0;
};
class CDerived : public CBase
{
public:
void Test(int iTest = 1) const { cout << iTest << endl; };
};
{
public:
virtual void Test(int iTest = 0) const = 0;
};
class CDerived : public CBase
{
public:
void Test(int iTest = 1) const { cout << iTest << endl; };
};
CBase *p = new CDerived;
p->Test();
p->Test();
不用惊奇,书中给出了答案:虚拟函数系动态绑定(dynamically bound),而缺省参数值却是静态绑定(statically )所以,<<Effective C++>>第38条告诉我们: 绝对不要重新定义继承而来的缺省参数。