[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Reference to a C++ object in GTK+ callbacks
- From: "Brian J. Tarricone" <bjt23 cornell edu>
- To: gtk-app-devel-list gnome org
- Subject: Re: Reference to a C++ object in GTK+ callbacks
- Date: Wed, 14 Dec 2005 11:28:53 -0800
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/14/2005 11:19 AM, Stephen Pollei wrote:
> 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.
IIRC, I believe the functions only have to be static in this case if
they're actually C++ class methods. Plain old C global functions don't
need to be static, though if they're only used in that one module,
there's no reason *not* to make them static, and it's good practice to
do so.
-brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
iD8DBQFDoHJ16XyW6VEeAnsRAiaqAJ0fCFNpf1k/+OSTqtxHUpDdKuD6QACfSkJT
3iqrkpsHfNp4+XzAnyLq+so=
=BnXm
-----END PGP SIGNATURE-----
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]