I found information about calling C ++ function pointers and call pointers in structs, but I need to call a pointer to a member function that exists inside the structure, and I could not get the syntax correctly. I have the following snippet inside a method in the MyClass class:
void MyClass::run() { struct { int (MyClass::*command)(int a, int b); int id; } functionMap[] = { {&MyClass::commandRead, 1}, {&MyClass::commandWrite, 2}, }; (functionMap[0].MyClass::*command)(x, y); } int MyClass::commandRead(int a, int b) { ... } int MyClass::commandWrite(int a, int b) { ... }
This gives me:
error: expected unqualified-id before '*' token error: 'command' was not declared in this scope (referring to the line '(functionMap[0].MyClass::*command)(x, y);')
Moving these parentheses around the results in syntax errors recommending use. * or โ * none of which work in this situation. Does anyone know the correct syntax?
source share