Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!warwick!nott-cs!christopher-robin.cs.bham.ac.uk!idf From: idf@cs.bham.ac.uk (Ian Fitchet ) Newsgroups: comp.lang.c++ Subject: Pointers to Member Functions Message-ID: <1369@christopher-robin.cs.bham.ac.uk> Date: 5 Dec 90 16:40:37 GMT Organization: University of Birmingham, England Lines: 57 I came across a problem while trying to explain pointers to functions from a C perspective in a C++ tutorial. This failed so I looked it up in a book which said that the following code should be valid. #include class foo { int a; public: foo() { a = 1; } void print() { cout << a << "\n"; } void bar() { a = 3; } }; main() { void (foo::*ptr2bar)() = &foo::bar; foo bletch; cout << "Initially a = " ; bletch.print(); bletch.(*ptr2bar)(); cout << "Finally a = "; bletch.print(); } The Sun C++ compiler (CC -v prints out "Sun C++ 2.0 FCS - 10/20/89") does the following: %cd /mbhome/staff/idf/src/cc/ %CC -o foo q.c %CC q.c: %"q.c", line 36: error: syntax error %1 error %cc -o /mbhome/staff/idf/src/cc/foo -c -I/usr/CC/incl % %Compilation exited abnormally with code 1 at Wed Dec 5 16:03:08 ie a syntax error on the call. g++ version 1.37.2 beta (based on GCC 1.37) does the following: %cd /mbhome/staff/idf/src/cc/ %g++ -o foo q.c %q.c: In function int main (): %q.c:30: parse error before `*' % %Compilation exited abnormally with code 1 at Wed Dec 5 16:32:09 ie gives a parse error on the declaration of ptr2bar void (foo::*ptr2bar)() = &foo::bar; Is it me, or are the compilers to blame? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ian Fitchet | "Have you heard the one about the FitchetI@uk.ac.bham.cs | orangutan and the pomegranate?" FitchetI%cs.bham.ac.uk@nsfnet-relay.ac.uk | - Gerald the Gorilla (NTNO'CN) Brought to you by Super Global Mega Corp .com