The question is simply in the title, if I have a function I want to use via a g_timeout_add()
, but this function is a class member function, is there any way I can use it with g_timeout_add()
?
views:
29answers:
1
+2
A:
You need to use a trampoline function, e.g.:
extern "C" gboolean trampoline(gpointer data) {
static_cast<MyClass*>(data)->mem_fun();
}
// ...
MyClass c = /* ... */;
g_timeout_add(/*...*/, static_cast<gpointer>(&c));
See this question on why you should use free functions if you want to write portable code.
Georg Fritzsche
2010-05-01 17:57:23