3 ms·
You can easily ignore null by accident while using smart pointers: struct foo { int bar; }; std::unique_ptr<foo> bug; bug->bar = 123;
by civility 9y ago
You can easily ignore null by accident while using smart pointers:
struct foo { int bar; };
std::unique_ptr<foo> bug;
bug->bar = 123;
- tomsmeding 9y agoTrue, didn't think of that. Then indeed they are quite useless, and IIRC they are actuallt deprecated in C++17.
- civility 9y agoI don't agree they are useless - they don't stop you from accessing nullptrs, but they do help manage the lifetimes of your dynamically created objects. And I haven't seen anything indicating unique_ptr is to be deprecated - maybe you're thinking about auto_ptr.
- albinofrenchy 9y agoSmart pointers are not at all useless and not at all deprecated (you are thinking of auto_ptr; there are still unique_ptr and shared_ptr). They don't try to address the check for null problem at all; that isn't their intent. All they mean to do is eliminate several classes of common, easy to make mistakes such as not zero initializing or not freeing the resource.