Re: [Cluttermm] Use of Glib::RefPtr<T> vs. Gtkmm
- From: Mark Roberts <gtkmm manumark de>
- To: Aarto Matti <aarto matti gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: [Cluttermm] Use of Glib::RefPtr<T> vs. Gtkmm
- Date: Mon, 15 Mar 2010 17:35:35 +0100 (CET)
Why Glib::RefPtr<T> is used in Clutter for smart-pointer management
everywhere and Gtkmm doesn't bother about that much?
We can create a button object with Gtk::Button *button =
But we have to struggle in Clutter with that mess:
Glib::RefPtr<Clutter::Actor> actor = new Clutter::Actor::create();
and not do like this:
Clutter::Actor* actor = new Clutter::Actor();
Smart pointers are not meant to be a struggle. Smart pointers are your
friends. With smart pointers the decision about an object's lifetime is
stated clearly at construction time, whereas a naked 'new' may belong to
one or several 'delete's anywhere in the program, or none at all,
if it's been forgotten.
Smart pointers make it easy to write exception safe code, whereas naked
'new's make it very very difficult.
In gtkmm, as you mention, you are allowed to do without smart pointers.
Yet you will find that many people choose to use them anyway, for instance
std::auto_ptr< Gtk::Button> button( new Gtk::Button());
Make friends with them, they are on your side.
All the best,
] [Thread Prev