You need to tell the compiler which class the foo
s are coming from (otherwise it thinks they’re functions from global scope):
void A::setPtr(int v){
if(v == 1){
_currentPtr = &A::foo1;
// ^^^^
} else {
_currentPtr = &A::foo2;
// ^^^^
}
}
and you need a set of parentheses here:
std::cout << (this->*_currentPtr)(4,5);
// ^ ^