This is the mail archive of the gcc-help@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: Pointer to a function forbid!!


Glover George wrote:

> Here's where I'm passing the address of
> gate.DeviceCallbakEventHandler() to a function (which is part of the
> Intel UPnP SDK, I'll put it's declaration below).
:
> I know there can be pointers to functions, but I'm not understanding
> why it won't work here.

Because it's a non-static class member function.

Non-static member functions expect to be passed (behind the scenes) the
address of the object that they were invoked on. They need this to use
as the value of their 'this' pointer. The language doesn't support
'binding' a function pointer and an object pointer together to use as a
pointer to that operation on that object.

If the function must be a member of Gate, and Gate has scope in main()
then you could give the Gate global scope and create a trivial wrapper
function also at global scope:

    int GateDeviceCallbackEventHandler(args)
    {
        return gate.DeviceCallbackEventHandler(args);
    }

I don't really like the idea of that from a 'cleanliness' viewpoint, but
if it must refer to a specific instance of a gate object then that's
probably the best way.

Rup.


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