GTK怎么和C++连接作界面?
GTK+ Tutorial中讲到了一种方法,但是我看不懂,有没有哪位大神会用,给个简单的例子介绍一下:
原文如下:
Second, you can use GTK and C++ together by declaring all callbacks as static functions in C++ classes, and again calling GTK using its C interface. If you choose this last approach, you can include as the callback's data value a pointer to the object to be manipulated (the so-called "this" value).
[解决办法]
GTK的话用C语言比较方便,GTKMM是它的C++绑定,所以你用C++的话它会相当方便。
struct test_t
{
void member_func () {}
static void static_func (void* data)
{
test_t* me = reinterpret_cast<test_t*>(data);
me->member_func();
}
};
int main ()
{
test_t t;
some_gtk_callback_register(test_t::static_func,&t);
}