2015-02-24 62 views
0

我收到一個我不明白的錯誤。我相信這很簡單..但我仍然在學習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; 
} 
+1

爲什麼你認爲'Rxmsg'可以用在需要HandlerType的地方? – 2015-02-24 05:40:07

+0

什麼是HandlerType? – Jagannath 2015-02-24 05:42:20

+0

'localnode :: RegisterHandler(123,'Rxmsg);可以在沒有對象的類中調用? – 2015-02-24 05:43:12

回答

1

在我看來,那bool RegisterHandler(int n, HandlerType & handler)需要對類HandlerType的一個對象的引用和你想傳遞一個函數。顯然這是行不通的。

所以我認爲你想要做的是通過*this而不是Rxmsg。這將爲RegisterHandler提供mine類的實例,現在可以在其上調用已覆蓋的函數Rxmsg

注意函數Rxmsg將按照這種方式在變量*this所具有的完全相同的Object上調用,此時您將其提供給RegisterHandler

我希望這是你打算做的,我希望我能幫助你。

0

RegisterHandler(123, Rxmsg);更改爲RegisterHandler(123, *this);解決了問題。謝謝!

+1

您的反饋意見將在上述答案的評論中,而不是爲自己的問題增加一個答案。請upvote並接受上述答案.. – 2015-02-26 06:15:44