Path: utzoo!attcan!uunet!taumet!mike From: mike@taumet.com (Michael S. Ball) Newsgroups: comp.lang.c++ Subject: Re: Address of member function Message-ID: <489@taumet.com> Date: 25 Oct 90 15:55:03 GMT References: <1392@carol.fwi.uva.nl> <12422@cadillac.CAD.MCC.COM> Reply-To: mike@taumet.UUCP (Michael S. Ball) Organization: Taumetric Corporation, San Diego Lines: 28 In article <12422@cadillac.CAD.MCC.COM> vaughan@mcc.com (Paul Vaughan) writes: > For a call-back mechanism, I want to store the address of a non-static > class member function. Turbo-C++ does not allow this ("member function > pointers are not true pointer types, and do not refer to any particular > instance of a class"). >Both Cfront and g++ accept this usage of member functions > >int (Foo::*f)() = Foo::foo; So does TC++, but this is not what he asked for. He wants the actual address of the function, which is not available in C++ except as an anachronism. Few compilers support this anachronism, and we hope that still fewer do in the future. The reason is obvious, and stated in the original postings, the functions must be bound to a class instance before they can be called, and there is no way to do this within the C++ language. For example, it's not acceptable to pass a pointer to an object as the first parameter, since the language gives no guarantees of how "this" is implemented. If you are dealing with an existing callback mechanism which insists on a pointer to an ordinary function, you must write such an ordinary function and have it call the member function (possibly through a pointer) bound to an actual object. -Mike-