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



On Tue, 2005-12-13 at 16:30 -0800, Stephen Pollei wrote:
On 12/13/05, Paul Santa Maria <paulsm1021 yahoo com> wrote:
I'm coding in C++, but using the "raw" GTK+ C
libraries.
I'm doing similiar for a game I'm making.

   ------------------
gboolean
play_cb (gpointer data)
{
  // Deference the object pointer to do the actual work
  AnimationFile *ani = (AnimationFile *)data;
  ani->start ();
}
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.

-- 
Daryl Lee
Open the Present--It's a Gift.




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