0

I have a C++ class which contains the following definition:

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;
}

later on in the c++ code i add values to the map variable using the following line:

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

and for execution within one of SomeClass's methods:

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);
}

I end up getting the following compilation error:

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

I even tried using the iterator explicitly - this->*iterator->second(...) but ended up with the same error.

what am i doing wrong? thanks

igal k
  • 1,883
  • 2
  • 28
  • 57
  • Please read how to make [good examples](http://stackoverflow.com/help/mcve). Well, yours is kind of good but could be better. ;-) – TobiMcNamobi Oct 30 '14 at 16:57

1 Answers1

1

() has higher precedence than ->* so pfParse(x) is evaluated first. You need to use parenthesis to sequence the evaluation:

(this->*pfParse)(x);
David G
  • 94,763
  • 41
  • 167
  • 253