Re: [Cluttermm] Use of Glib::RefPtr<T> vs. Gtkmm

Hi Aarto,

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 =
new Gtk::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,

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