auto fancyObjectPtr = std::make_shared<MyFancyObject>();
std::shared_ptr handles the allocation, deallocation, and lifetime. Alternatively, if you know you're only ever going to have one pointer to the object, you can use std::unique_ptr.
Even still, it's good to know how to use new; every now and then, you still need it.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You still need to use manual memory allocation to instantiate many custom objects.
However, even if you do need to handle manual memory allocation, smart pointers handle nearly all of the scenarios where you'd need it.
Or, thanks to the relatively new
auto
keyword...std::shared_ptr
handles the allocation, deallocation, and lifetime. Alternatively, if you know you're only ever going to have one pointer to the object, you can usestd::unique_ptr
.Even still, it's good to know how to use
new
; every now and then, you still need it.