Re: Using g_signal_connect in class
- From: Chris Vine <chris cvine freeserve co uk>
- To: "Vallone, Anthony" <anthony vallone lmco com>
- Cc: gtk-list gnome org
- Subject: Re: Using g_signal_connect in class
- Date: Sat, 19 Jul 2008 12:29:15 +0100
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]