This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Address of a member function at an object
- From: Mike Stump <mrs at apple dot com>
- To: Mustafa Celik <celikmus at hotmail dot com>
- Cc: gcc at gnu dot org
- Date: Wed, 9 Oct 2002 13:29:05 -0700
- Subject: 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.