I found something interesting. The error message says it all. What is the reason behind not allowing parentheses while taking the address of a non-static member function? I compiled it on gcc 4.3.4.
#include <iostream>
class myfoo{
public:
int foo(int number){
return (number*10);
}
};
int main (int argc, char * const argv[]) {
int (myfoo::*fPtr)(int) = NULL;
fPtr = &(myfoo::foo); // main.cpp:14
return 0;
}
Error: main.cpp:14: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&myfoo::foo'
classname::
. Also doesn't answer what I'm most curious about, which is why (in a why was this decided on sense) are the parens disallowed? – Hatfield&
, while in the question you linked the issue was that the OP was using a regular function pointer instead of a member function pointer. – Livornothis
pointer later. – Lentha