How to use std::unique_ptr and std::shard_ptr
-
Hi
Have a nice day .I need to know std::unique_ptr and std::shard_ptr ,I tryed to use that two items inside the Qt creater but if i used std:: its not genarate these two items and i also used #include<memory> but still i can't use these two items please anyone have working examples please share with me :)
Thanks
-
there are also Qt flavors for it.
"QScopedPointer":http://qt-project.org/doc/qt-5.0/qtcore/qscopedpointer.html
"QSharedPointer":http://qt-project.org/doc/qt-5.0/qtcore/qsharedpointer.html -
For projects not using C++11 QScopedPointer, QSharedPointer and QWeakPointer are great, however for projects using C++11 I would use std::unique_ptr, std::shared_ptr and std::weak_ptr.
A big plus IMHO is also that std::unique_ptr can be used in containers while you can not do this with QScopedPointer.
-
[quote author="PeerS" date="1367849422"]For projects not using C++11 QScopedPointer, QSharedPointer and QWeakPointer are great, however for projects using C++11 I would use std::unique_ptr, std::shared_ptr and std::weak_ptr.
A big plus IMHO is also that std::unique_ptr can be used in containers while you can not do this with QScopedPointer.[/quote]
Agreed
Actually, I have been using boost's shared_ptr for a long time. So, it is not limited to C++11. However, boost's docs are not great when you start with. Qt's docs are much better. ... and since this is a Qt forum, I thought we should notice at least ;-) -
[quote author="koahnig" date="1367851801"]
... and since this is a Qt forum, I thought we should notice at least ;-)
[/quote]They are absolutely worth to be mentioned :)
To be honest, before reading your post I did not even know about the Qt smart pointers even though I use Qt since several years now.
Peer -
[quote author="PeerS" date="1367852418"]
They are absolutely worth to be mentioned :)
To be honest, before reading your post I did not even know about the Qt smart pointers even though I use Qt since several years now.
Peer
[/quote]Somehow this sounds familiar. I have learnt about those pointers also through this forum. :-)