Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!ames!sun-barr!male!pitstop!texsun!pollux!ti-csl!mips!neath From: neath@solar-1.stars.flab.Fujitsu.JUNET Newsgroups: comp.lang.c++ Subject: Pointers/References to Member Functions Message-ID: Date: 3 May 89 03:40:20 GMT Sender: news@ti-csl.csc.ti.com Distribution: comp.lang.c++ Organization: Texas Instruments Data Systems Group, Austin TX Lines: 33 A recent posting to this group discussed the use of typedef to specify a type that is a `pointer to a member function of class X'. Can this be extended to include a reference to a member function? If not, why not? Specifically, the following code fragment results in a "internal <> error: bus error" message: class A { int a; public: A(int n) {a = n;}; void print() {cout << a;}; }; typedef void A::MEMF; MEMF* p1 = A:print; // This is accepted by cfront MEMF& p2 = *A:print; // This results in bus error! What I am really trying to do is see if there is a mechanism that can be used to implement features similar to BEFORE, AFTER, and AROUND methods found in Lisp. If I can get access to the pointer maintaining the link to the member function of a class, I can change this to point to some function implementing the appropriate method behavior. This functionality greatly facilitates code reuse, since it becomes much easier to take an existing class and make a slight modification to it without having to derive a new class from it. Any comments? Regards Martin Neath ------------------------------------------------------------------------ DISCLAIMER: As always, the opinions expressed above are strictly my own and do not reflect those of my employer, Texas Instruments. ------------------------------------------------------------------------ -- Regards, Martin