Allow me add something to what the FAQ-Xt says.
I find it more convenient to immediately call a non-static
function as shown below (using a slightly modified example
from the FAQ).
class Icon {
public:
Icon(Widget*);
private:
static void static_callback(Icon*);
inline void real_callback();
Widget* button;
int count;
...
};
Icon::Icon(Widget* parent): count(0)
{
button = XtVaCreateWidget("Boo!", xmPushButtonWidgetClass, parent, 0);
XtAddCallback(button, XmNselectCallback, &Icon::static_callback,
(XtPointer)this);
...
}
inline void
Icon::real_callback()
{
count++;
...
}
void
Icon::static_callback(Icon* icon)
{
icon->real_callback();
}
The reason for calling real_callback from static_callback is
to avoid having to specify icon->count etc. to reference
components of the Icon object. This makes a difference in
readability if your callback function does a bunch of stuff.
The reason for inlining to not incur the cost of an
additional call (if this matters -- usually it doesn't).
Inlining can get in your way during debugging (atleast gdb
loses its mind) so provide a way to disable it. BTW, this
idiom is useful pretty much any time you have to use C++
callbacks from C code, not just for X11.
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message