Re: Using g_signal_connect in class

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

 



On Tue, 15 Jul 2008 11:34:41 -0400
"Vallone, Anthony" <anthony.vallone@xxxxxxxx> wrote:

> Only if the member function is static.  Calling a non-static member
> function requires two addresses: the instance address and the function
> address.  Whether its public or private doesn't matter because access
> to function pointers is not checked by compilers.  I frequently do
> something like this:
> 
> class SomeClass
> {
>   ...
> private:
>   ...
>   static void staticCb(..., gpointer inInstance) {
>     SomeClass* instance = (SomeClass*)inInstance;
>     instance->callback(...);
>   }
>   void callback(...) {
>     ...
>   }
>   ...
>   void someFunc() {
>     ...
>     g_signal_connect(..., G_CALLBACK(&staticCb), this);
>     ...
>   }
>   ...
> };

This will work with gcc/g++ but it is not standard conforming, as
static class functions do not have C linkage, and the C++ standard
states that functions otherwise identical with C++ and C linkage are
different types.

To be standard conforming you should use a friend function (if it needs
access to private data) declared extern "C".

Chris

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux