Re: Using g_signal_connect in class
- From: Jean Bréfort <jean brefort normalesup org>
- To: Chris Vine <chris cvine freeserve co uk>
- Cc: "Vallone, Anthony" <anthony vallone lmco com>, gtk-list gnome org
- Subject: Re: Using g_signal_connect in class
- Date: Sat, 19 Jul 2008 13:42:58 +0200
Le samedi 19 juillet 2008 à 12:29 +0100, Chris Vine a écrit :
> On Tue, 15 Jul 2008 11:34:41 -0400
> "Vallone, Anthony" <anthony vallone lmco com> 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
The extern "C" declaration is not needed.
Regards,
Jean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]