对未解析的重载函数类型的调用没有匹配的函数
No matching function for call to unresolved overloaded function type
我遇到了一个我不理解的错误。我相信这很简单。。但我仍在学习C++。我不确定这是否与纯虚拟函数声明的参数完全相同有关,或者是其他原因。
这是我的简化代码:
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;
}
在我看来,bool RegisterHandler(int n, HandlerType & handler)
引用了类HandlerType
的对象,而您正试图传递一个函数。显然,这是行不通的。
所以我认为你想做的是传递*this
而不是Rxmsg
。这将为RegisterHandler
提供一个类mine
的实例,现在可以在该实例上调用被重写的函数Rxmsg
。
请注意,如果这样做,函数Rxmsg
将在变量*this
提供给RegisterHandler
时的同一对象上调用。
我希望这是你打算做的,我希望我能帮助你。
将RegisterHandler(123, Rxmsg);
更改为RegisterHandler(123, *this);
解决了问题。谢谢
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 返回指向对象的指针的函数调用是否为 prvalue?
- C++ 如何重载 [] 运算符并进行函数调用
- 代码的效率. 转到和函数调用
- 是同一作用域的函数部分中的函数调用
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 类型擦除的std::function与虚拟函数调用的开销