Blanda C- och C++-API:er
Du kan använda C-API:er som inte ännu har praktiska C++-gränssnitt. Det är allmänt inte ett problem att använda C-API:er från C++, och gtkmm hjälper till genom att ge åtkomst till det underliggande C-objektet, och tillhandahåller ett lätt sätt att skapa ett C++-omslagsobjekt från ett C-objekt, givet att C-API:t också är baserat på GObject-systemet.
To use a gtkmm instance with a C function that requires a C GObject instance, use the C++ instance’s gobj() function to obtain a pointer to the underlying C instance. For example:
Gtk::Button button("example");
gtk_button_do_something_that_gtkmm_cannot(button.gobj());
To obtain a gtkmm instance from a C GObject instance, use one of the many overloaded Glib::wrap() functions. The C instance’s reference count is not incremented, unless you set the optional take_copy argument to true. For example:
GtkButton* cbutton = get_a_button();
Gtk::Button* button = Glib::wrap(cbutton);
button->set_label("Now I speak C++ too!");
it's a widget or other class that inherits from Gtk::Object, and
the C instance has a floating reference when the wrapper is created, and
Gtk::manage() has not been called on it (which includes if it was created with Gtk::make_managed()), or
Gtk::manage() was called on it, but it was never added to a parent.
In all other cases the C++ instance is automatically deleted when the last reference to the C instance is dropped. This includes all Glib::wrap() overloads that return a Glib::RefPtr.