[英]No matching function for call to unresolved overloaded function type
I am getting an error which I don't understand. 我收到一个我不明白的错误。 I'm sure it is quite simple.. but I am still learning C++.
我敢肯定这很简单..但是我仍在学习C ++。 I'm not sure if it is related to my parameters being exactly the same for the pure virtual function declaration or if it is something else.
我不确定它是否与我的参数有关(对于纯虚函数声明)完全相同,还是其他原因。
Here is my simplified code: 这是我的简化代码:
in header_A.h
class HandlerType
{
public:
virtual void Rxmsg(same parameters) = 0; //pure virtual
};
--------------------------------------------------
in header_B.h
class mine : public HandlerType
{
public:
virtual void myinit();
void Rxmsg(same parameters); // here I have the same parameter list
//except I have to fully qualify the types since I'm not in the same namespace
};
--------------------------------------------------
in header_C.h
class localnode
{
public:
virtual bool RegisterHandler(int n, HandlerType & handler);
};
--------------------------------------------------
in B.cpp
using mine;
void mine::myinit()
{
RegisterHandler(123, Rxmsg); //this is where I am getting the error
}
void Rxmsg(same parameters)
{
do something;
}
It seems to me, that bool RegisterHandler(int n, HandlerType & handler)
takes a reference to an object of the class HandlerType
and you're trying to pass a function. 在我看来,
bool RegisterHandler(int n, HandlerType & handler)
引用了HandlerType
类的对象,而您正在尝试传递一个函数。 Obviously that doesn't work. 显然,这是行不通的。
So I think what you wanna do is passing *this
instead of Rxmsg
. 所以我想您想做的是传递
*this
而不是Rxmsg
。 This will supply RegisterHandler
with an instance of the class mine
, on which the overridden function Rxmsg
can now be invoked. 这将为
RegisterHandler
提供类mine
的实例,现在可以在其上调用重写函数Rxmsg
。
Notice that the Function Rxmsg
will, if done that way, be called on the exact same Object that the variable *this
had, at the moment you supplied it to RegisterHandler
. 请注意,如果这样做,函数
Rxmsg
将在变量*this
具有的对象上被完全调用,而此对象已被提供给RegisterHandler
。
I hope this is what you intended to do and I hope I could help you. 我希望这是您打算做的事,希望我能为您提供帮助。
Changing RegisterHandler(123, Rxmsg);
更改
RegisterHandler(123, Rxmsg);
to RegisterHandler(123, *this);
到
RegisterHandler(123, *this);
Solved the problem. 解决了问题。 Thanks!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.