I’m trying to pass a member function as an argument. Basically I have a class called AboutWindow, and the header looks as this (trimmed for brevity):
class AboutWindow
{
private:
AboutWindow(void);
~AboutWindow(void);
public:
int AboutWindowCallback(XPWidgetMessage inMessage, XPWidgetID inWidget, long inParam1, long inParam2);
};
and in the source I am trying to pass the AboutWindowCallback member function as a (pointer to / reference to) the function.
It looks something like this:
XPAddWidgetCallback(widgetId, this->AboutWindowCallback);
but I am getting the following IntelliSense warning:
A pointer to a bound function may only
be used to call the function
Is it possible to pass the member function to XPAddWidgetCallback. Note it has to be that specific function, of that specific instance, as inside the AboutWindowCallback function, the this keyword is used.
Thanks in advance!
I assume you’re using x-plane here.
Unfortunately XPAddWidgetCallback expects a callback in the form of
You provided a class member function. It would work if this were a global function. So this :
Would be correct.
However, it’s not nice to have to have global functions for that, as noted in this thread on x-plane.
To circumvent that, have a look at the Wrapper class example “XPCWidget.cpp” that is supplied with x-plane, or use tr1/boost bind to wrap the callback.
You can also make the function in question
static: