无匹配功能 - 专业签名隐藏通用?
我刚刚遇到了以下 C++ 编译器错误:
no matching function for call "EPTDerivedException::HandleClass( BaseClass& )"
candidates are: void EPTDerivedException::HandleClass( DerivedClass )
我无法解释这一点,因为应该有一个函数 HandleClass( BaseClass )。这是调用代码:
BaseClass oBase;
EPTDerivedException* pException2 = new EPTDerivedException;
pException2->HandleClass( oBase );
这是 EPTDerivedException 的代码:
class EPTDerivedException : public EPTException
{
public:
EPTDerivedException();
// generic function
void HandleClass( DerivedClass oClass ) { Q_UNUSED(oClass); }
};
对于基类:
class EPTException
{
public:
EPTException( QString strName );
// specialized function
void HandleClass( BaseClass oBase ) { Q_UNUSED(oBase); }
private:
QString m_strName;
};
奇怪的是,当我重新编译(make clean;make)代码时,我收到错误消息。如果我在调用代码(main.cpp)中添加一个空格“” - 之后编译成功 - 我不知道为什么......
非常感谢,
Charly
PS:我使用 gcc 4.4.5 和 Debian Squeeze, qt-creator 作为 qt 4.6 的 IDE - 但这个问题与 Qt 无关。
I just got stuck with the following C++ compiler error:
no matching function for call "EPTDerivedException::HandleClass( BaseClass& )"
candidates are: void EPTDerivedException::HandleClass( DerivedClass )
I cannot explain this, because there should be a function HandleClass( BaseClass ). This is the calling code:
BaseClass oBase;
EPTDerivedException* pException2 = new EPTDerivedException;
pException2->HandleClass( oBase );
And this is the code for EPTDerivedException:
class EPTDerivedException : public EPTException
{
public:
EPTDerivedException();
// generic function
void HandleClass( DerivedClass oClass ) { Q_UNUSED(oClass); }
};
And for the base class:
class EPTException
{
public:
EPTException( QString strName );
// specialized function
void HandleClass( BaseClass oBase ) { Q_UNUSED(oBase); }
private:
QString m_strName;
};
The strange things is also, that when I recompile (make clean; make) the code, I get the error message. If I add a space " " in the calling code (main.cpp) - the compiling afterwards is successful - and I have no idea why...
Thanks a lot,
Charly
PS: I use gcc 4.4.5 with Debian Squeeze, the qt-creator as IDE with qt 4.6 - but this problem is independent from Qt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么你认为应该有一个 EPTDerivedException::HandleClass( BaseClass oBase ) 函数。没有这样的声明。
也许您需要将
using EPTException::HandleClass;
添加到EPTDerivedException
?I'm not sure why you think there should be a
EPTDerivedException::HandleClass( BaseClass oBase )
function. There's no such declaration.Perhaps you need to add
using EPTException::HandleClass;
toEPTDerivedException
?