Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!src.honeywell.com!msi.umn.edu!cs.umn.edu!ianhogg From: ianhogg@cs.umn.edu (Ian J. Hogg) Newsgroups: comp.lang.c++ Subject: Re: Pointers to Member Functions Message-ID: <1990Dec7.053119.18866@cs.umn.edu> Date: 7 Dec 90 05:31:19 GMT References: <1369@christopher-robin.cs.bham.ac.uk> Organization: University of Minnesota, Minneapolis - CSCI Dept. Lines: 35 In article <1369@christopher-robin.cs.bham.ac.uk> idf@cs.bham.ac.uk (Ian Fitchet ) writes: > > 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)(); ^^^^^^^^^^^^^^^^^^^^^^ (bletch.*ptr2bar)(); > cout << "Finally a = "; > bletch.print(); >} > Compiles and runs fine on HP's cfront 2.0. Lippman's book discusses this on pages 211-212. ============================================================================== Ian Hogg ian@dms.cdc.com