简体   繁体   English

没有匹配的函数可调用未解析的重载函数类型

[英]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.

相关问题 没有匹配的 function 可以打电话给<unresolved overloaded function type></unresolved> - no matching function for call to <unresolved overloaded function type> 没有匹配的函数无法调用未解析的重载函数类型 - no matching function for call unresolved overloaded function type “没有匹配的函数可以调用...未解析的重载函数类型” - “No matching function for call to… unresolved overloaded function type” 没有用于调用std :: transform,未解析的重载函数类型的匹配函数 - No matching function for call to std::transform, unresolved overloaded function type 错误:没有匹配的函数可以调用&#39;sort(...,…, <unresolved overloaded function type> )&#39; - error: no matching function for call to 'sort(…, …, <unresolved overloaded function type>)' 没有匹配的函数来调用&#39;QDomDocument :: createElement( <unresolved overloaded function type> )&#39; - no matching function for call to 'QDomDocument::createElement(<unresolved overloaded function type>)' 重载的电话*** <unresolved overloaded function type> )&#39;不明确 - call of overloaded *** <unresolved overloaded function type>)' is ambiguous 没有匹配的函数来调用&#39;std :: list <int, std::allocator<int> &gt; :: sort( <unresolved overloaded function type> )&#39; - No matching function for call to 'std::list<int, std::allocator<int> >::sort(<unresolved overloaded function type>)' “没有匹配函数来调用'async(std :: launch,<unresolved overloaded function type>,std :: string&)'” - “no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’” 错误:没有匹配的函数调用 &#39;sf::RenderWindow::draw(<unresolved overloaded function type> )&#39; SFML C++ - Error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)' SFML C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM