tags:

views:

217

answers:

1

Hi Guys,

More GTK questions, im trying to compile some code and im getting the following error:

error: invalid use of member (did you forget the ‘&’ ?)

This is comming from the g_signal_connect call:

g_signal_connect ((gpointer) Drawing_Area_CPU, "expose-event", 
        G_CALLBACK (graph_expose), NULL);

Drawing_Area_CPU is a GtkWidget* and graph_expose is defined as:

gboolean graph_expose(GtkWidget *widget, GdkEventExpose *event, gpointer data);

So far as i can tell im doing everything right, but still i get this error. Can anyone help please?

Regards

Paul

UPDATE:

Sorry guys, i got confused, my graph_expose function is in a class, and im trying to do the g_signal_connects from the constructor of that class, would that affect this problem in any way?

A: 

As GTK+ is written in plain C, callbacks have to be either plain functions or static methods, so if you want to be able to use class methods as callbacks, you must use some kind of static proxy method:

class foo {
    foo () {
        g_signal_connect (GtkWidget *widget, GdkEventExpose *event,
                          G_CALLBACK (foo::graph_expose_proxy), this);
    }

    gboolean graph_expose (GtkWidget *widget, GdkEventExpose *event) {
        // sth
    }

    static gboolean graph_expose_proxy (GtkWidget *widget, GdkEventExpose *event, gpointer data) {
        foo *_this = static_cast<foo*>(data);
        return _this->graph_expose (widget, event);
    }
}

Or, alternatively, you could use GTKmm, which is C++ binding for GTK+.

el.pescado
Unless you want your code to break unexpectedly, use free functions when you need C-callbacks - for why see e.g. here: http://stackoverflow.com/questions/2068022/in-c-is-it-safe-portable-to-use-static-member-function-pointer-for-c-api-callb
Georg Fritzsche