When returning a member function pointer to a class within one of that class's member functions I still have to specify the class. I cannot simply take the address. For example, this code works fine:
class Foo {
public:
void func(int param) { cout << param << endl; }
void (Foo::*getPointer())(int) { return &Foo::func; }
};
But if in getPointer
I try to simply do: return &func
I get this error:
prog.cpp: In member function '
void (Foo::* Foo::getPointer())(int)
':
prog.cpp:8:43: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&Foo::func
' [-fpermissive]
void (Foo::*getPointer())(int) { return &func; }
Why must I specify the class when that's the context that I am within?