Re: Reference to a C++ object in GTK+ callbacks



On 12/13/05, Daryl Lee <dlee altaregos com> wrote:
Are you sure that is the right style for that callback?
static void
rocket_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
        class city_node *city=static_cast<class city_node *>(data);
        global_game.rocket_up(*city);
        city->update_targets();
        each_tick(NULL);
}

C++ functions do, indeed, have to be "static" to be used as GTK+
callbacks.
Untrue I just removed the static keyword from 8 of my callbacks and
then recompiled, worked just fine. As Andy Grebe of apogeelabs said
"... function needs to have the correct format".
That I bet was the problem. That I label a lot of my callbacks with
"static", I just consider good style.
diff -u1 gtk_main.cc-save gtk_main.cc > static-out.diff

The only c++ problem I can see is if you had overloaded functions; I
can't think of how you'd select which one you meant.

--
http://dmoz.org/profiles/pollei.html
http://sourceforge.net/users/stephen_pollei/
http://www.orkut.com/Profile.aspx?uid=2455954990164098214
http://stephen_pollei.home.comcast.net/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]