2014-10-30 42 views
0

我有一個C++類,其中包含了以下定義:評價C++函數指針表達

class SomeClass: 
    public BaseClass 
{ 
public: 
    SomeClass(); 
    bool SomeClass::MyFunc(Json::Value& jsonRoot) 

    typedef bool(SomeClass::*PFUNC)(Json::Value&); 
    std::map<std::string, PFUNC> m_map; 
} 

稍後在C++代碼,我使用下面的行添加值到地圖變量:

SomeClass::SomeClass() 
{ 
    m_map["func"] = &SomeClass::MyFunc; 
} 

併爲SomeClass的的方法之一中執行:

std::map<std::string, PFUNC>::iterator itFunction = m_map.find("func"); 
if (itFunction != m_map.end()) 
{ 
    PFUNC pfParse = m_map["func"]; 
    Json::Value x; 
    this->*pfParse(x); 
} 

我最終得到的以下編譯錯誤:

error C2064: term does not evaluate to a function taking 1 arguments 

我甚至使用迭代明確地嘗試 - 這 - > * iterator->第二(...),但結束了同樣的錯誤。

我在做什麼錯? 謝謝

+0

請閱讀如何製作[很好的例子](http://stackoverflow.com/help/mcve)。那麼,你的很好,但可能會更好。 ;-) – TobiMcNamobi 2014-10-30 16:57:28

回答

1

()->*具有更高的優先級,因此首先對pfParse(x)進行評估。你需要使用圓括號來評估順序:

(this->*pfParse)(x);