RE: [gtk-list] Re: Member functions as callbacks?




My last reply seems to have been mangled, so I`ll try again...

On 22-Jan-98 Robert Roebling wrote:
>Jonathan Belson wrote:
>
>> Hope I'm not overlooking anything obvious here, but I`m having problems
>> when I try and use member functions as callback functions, eg.
>
>Maybe you forgot, that C++ pushes the "this" operator on the
>stack as the first parameter when calling class member
>functions, so your code probably cannot work. Try something
>like this

I thought the 'this' argument would be removed transparently...obviously
not.

>void my_button_callback( GtkWidget *button, preview* win )
>{
>  win->button_pressed( button, "pressed" );
>};
>
>preview::open_window(void)
>{
>  // snip
>
>  gtk_signal_connect(GTK_OBJECT(button), "clicked",
>    GTK_SIGNAL_FUNC(my_button_callback),  (gpointer) this );
>
>  gtk_widget_show(button);
>}
>
>void preview::button_pressed(GtkWidget *widget, gpointer p)
>{
>  g_print("Button pressed\n");
>}

Thanks for the example, but it would be a shame to have to do things like this,
namely having a private function globally accessable.

I had a look at the source of Mnemonic which appeared to do something
similar to what I`m attempting in one of its source file.  Unfortunately I
couldn`t get the program to compile, so I couldn`t experiment with it.

C-YA
Jon



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