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()
?
Asked
Active
Viewed 335 times
1 Answers
2
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.

Community
- 1
- 1

Georg Fritzsche
- 97,545
- 26
- 194
- 236