[Bug c++/52453] New: compiling error when get address of a virtual function(invalid use of non-static member function)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453 Bug #: 52453 Summary: compiling error when get address of a virtual function(invalid use of non-static member function) Classification: Unclassified Product: gcc Version: 4.2.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: wildpointe...@gmail.com Version:gcc4.2.4, System :Ubuntu Linux 2.6.24 The preprocessed file: # 1 "test.cpp" # 1 "" # 1 "" # 1 "test.cpp" class Test { public: virtual void func(char *p){} }; int main() { typedef void (Test::*pTestfunc)(char *); pTestfunc pf = &(Test::func); // error here. } Error message: invalid use of non-static member function 'virtual void Test::func(char *)'
[Bug c++/52453] compiling error when get address of a virtual function(invalid use of non-static member function)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453 --- Comment #2 from Allen Wu 2012-03-01 16:40:07 UTC --- Thank you for your response. But I cannot see any difference between &Test::func and &(Test::func). Does C++ standard specify &(Test::func) is illegal? Thanks in advance. Allen 2012/3/2 redi at gcc dot gnu.org > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453 > > Jonathan Wakely changed: > > What|Removed |Added > > > Status|UNCONFIRMED |RESOLVED > Resolution||INVALID > > --- Comment #1 from Jonathan Wakely 2012-03-01 > 16:34:29 UTC --- > GCC 4.2 is no longer supported, but it doesn't matter because your code is > invalid anyway. > > To take the address of a member function you must not use parentheses > around > the expression: > >pTestfunc pf = &Test::func; > > -- > Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email > --- You are receiving this mail because: --- > You reported the bug. >