Hi, Compile the following program using g++ -c <file> on Red Hat 7.0 with latest gcc updates applied. //---------------------------------------------------------------- class MyClass { public: void MyClass::foo(); }; typedef void (MyClass::*MBF)(); void MyClass::mbf() { MBF f1 = &foo; // THIS DOESN'T WORK MBF f2 = &MyClass::foo; // THIS WORKS } //---------------------------------------------------------------- You'll get the following error message: foo.cc: In method `void MyClass::foo ()': foo.cc:9: ISO C++ forbids taking the address of a non-static member function to form a pointer to member function. Say `&MyClass::foo' The error message is curious. Why can't I take the address of a 'member function' to form a pointer to a 'member function'? I couldn't find any explanation about such issues in the standard. Even if this is not a bug, consider improving the message.
Read [expr.unary.op]/3 which sais at the end: Nor is &unqualified-id a pointer to member, even within the scope of unqualified-id's class. You can use `-fms-extensions' Disable pedwarns about constructs used in MFC, such as implicit int and getting a pointer to member function via non-standard syntax. switch though (see info gcc).
Hi, Indeed I can disable the error message using `-fms-extensions' however this is not the point. My point is that the error message should be ISO C++ forbids taking the address of an unqualified member function to form a pointer to member function. instead of ISO C++ forbids taking the address of a non-static member function to form a pointer to member function. Sorry I wasn't clear enough in the first place. I was a bit lost as I was struggling to find the relevant paragraph in the ISO C++ standard...
I've changed it to ISO C++ forbids taking the address of an unqualified non-static member function to form a pointer to member function. (both in my tree and in CVS head). It will appear in gcc-c++-2.96-76.