3 ms·
First off, new/delete are only used for objects that are allocated on the heap. Even then, modern C++ has RAII wrappers such as std::unique-ptr. You should only
by spacechild1 4y ago
First off, new/delete are only used for objects that are allocated on the heap. Even then, modern C++ has RAII wrappers such as std::unique-ptr. You should only need new/delete in rare cases.
- nlehuen 4y agoThis. Over the last few years of writing C++ on a daily basis, I can count the number of times I used `delete` on both hands (maybe one hand actually). `new` was harder to get rid of because of some flaw in the framework we used, but that has been fixed now. Unless you are in the business of writing smart pointers yourself, you should never have to use those keywords anymore.
- deleted 4y ago[deleted]
- torstenvl 4y agoBy default, unique_ptr calls delete. It therefore still calls the destructor. So this has literally no bearing on the problem. It doesn't help at all.
- spacechild1 4y agoOf course it calls the destructor. What else should it do? The point is that you don't get any double frees, because you never have to call delete manually. Or maybe I misunderstood your complaint?