If I had an option to choose between QScopedPointer
and boost::scoped_ptr
, which one would do most good in the following cases:
1. QScopedPointer<QObject> Vs boost::scoped_ptr<QObject>
2. QScopedPointer<QtContainer> Vs boost::scoped_ptr<QtContainer>
3. QScopedPointer::data() Vs boost::scoped_ptr::get()
They both do basically the same thing. The Qt version seems to have the ability to abscond with the pointer (
QScopedPointer::take()
), which allows you to transfer ownership to someone else. You can't do that withscoped_ptr
, but you can swap both kinds.boost::scoped_ptr
andQScopedPointer
are also is explicitly non-copyable.QScopedPointer
does have a mechanism that allows you to pass a "deleter" to the pointer. This is effectively a public static member of the given class, soQScopedPointer
is still only the size of a pointer. It does mean that the type ofQScopedPointer
must include the deleter's type.Both of them are made obsolete by
std::unqiue_ptr
in C++0x.