【发布时间】:2015-06-12 14:02:11
【问题描述】:
我有一个带有虚函数的基类 - int Start(bool)
在派生中有一个名称相同但签名不同的函数 -
int Start(bool, MyType *)
但不是虚拟的
在派生的Start()中,我想调用基类Start()
int Derived::Start(bool b, MyType *mType)
{
m_mType = mType;
return Start(b);
}
但它给出了编译错误。
"Start' : function does not take 1 arguments"
但是Base::Start(b) 有效
在 C# 中,上述代码有效,即解析调用不需要对 Base 的引用。
外部如果调用如下
Derived *d = new Derived();
bool b;
d->Start(b);
失败并显示消息:
Start : function does not take 1 arguments
但在 C# 中,同样的场景也适用。
据我了解,虚拟机制不能用于解析调用,因为这两个函数具有不同的签名。
但呼叫没有按预期得到解决。
请帮忙
【问题讨论】:
-
它们必须完全匹配——否则它会重载
-
In C#, the above code worksC# 不是 C++。