I have a class member function that needs to call other class member functions depending on an integer value, like this:
class foo {
public:
foo() {
mTestMap[1] = (*this).test1;
mTestMap[2] = (*this).test2;
mTestMap[3] = (*this).test3;
}
bool test1 () {}
bool test2 () {}
bool test3 () {}
bool execute_test(int test_num) {
if (mTestMap.count(test_num) > 0)
return mTestMap[test_num]();
return false;
}
std::map<int,std::function<bool()>> mTestMap;
};
The problem is, this code results in a compilation error:
Error C3867 'foo::test1': non-standard syntax; use '&' to create a pointer to member
What am I doing wrong? I know that I can assign a member function through a pointer to a specific object to a std::function. Something similar works if the map and the assignment occur outside the class. Why not from inside the class?