This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Address of a member function at an object


On Wednesday, October 9, 2002, at 01:16 PM, Mustafa Celik wrote:
Can I get the address of a member function with the code below?
No.  C++ does not allow this.

class Fred
{
public: void foo();
};

Fred fred;

void (*fp)() = &fred.foo;
// or
// void(Fred::*fp)() = &fred.foo;
// or ...

It doesn't compile with gcc 2.95.1, though I think it used to work with earlier compilers. It works for the following code:

void (Fred::*fp)() = &Fred::foo;

Is this a restriction, is there a work-around to get the address of a member function at that object?
This is C++.  I'd recommend a book about C++, or a C++ newsgroup FAQ.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]