开发者

QScopedPointer Vs boost::scoped_ptr [which one to choose]

If I had 开发者_如何学Goan 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 with scoped_ptr, but you can swap both kinds.

boost::scoped_ptr and QScopedPointer 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, so QScopedPointer is still only the size of a pointer. It does mean that the type of QScopedPointer must include the deleter's type.

Both of them are made obsolete by std::unqiue_ptr in C++0x.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜