Re: Calling C++ functions



On Wed, 2002-06-26 at 14:27, William L. Thomson Jr. wrote:
On Wed, 2002-06-26 at 08:28, Shahms E. King wrote:
If you're trying to do C++ things in GTK+ you might want to have a look
at GtkMM (http://www.gtkmm.org). It's a C++ binding for GTK+ that takes
care of a lot of those issues for you.

GtkMM looks nice, but it seems like an additional item that is not
included in my Linux distro RedHat 7.3.

Whether it will be in future RedHat releases?

I don't know about this, but there are RPMS for the stable version of
GtkMM (Gtk+ 1.2 based) for RedHat 7.x in Red Carpet (or from
ftp.ximian.com, if you don't want to use RC).


But in the end will it be worth it. Does GtkMM keep up with the GTK API
development, and what kind of overhead will it add to my apps if any?

I can't speak to the overhead, but from what I've seen they tend to
follow the API pretty completely.  GtkMM is currently in the process of
wrapping GTK2, but the GTK 1.2 bindings are pretty complete and very
usable.  And even in there present state the GTK2 bindings appear to be
usable, although I'm not sure how complete they are.

another alternative, for the callback binding is to use an ordinary
(non-member) function and pass in the instance you want to call the
member function of as the last parameter, and use the "C-style" function
to cast and call the appropriate member function, something like:

        button = gtk_button_new_with_label ("Hello, World!");
        g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK
(my_callback), &test);

void my_callback (GtkWidget* widget, gpointer data) 
{
        TestClass* test = (TestClass*)data;
        test->display ();
}

And make sure you cast the function to a G_CALLBACK (or GTK_SIGNAL_FUNC)
or g++ errors because the "types" (prototypes) don't match.


--Shahms



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