5 ms·
The counterpoint to this is the C developer who promises they can scale up to C++ and then takes a disproportionate amount of review time to be taught not to us
by thrwyoilarticle 4y ago
The counterpoint to this is the C developer who promises they can scale up to C++ and then takes a disproportionate amount of review time to be taught not to use malloc/free/new/delete/etc.
- Aeolun 4y agoThis is why I say I can do any language but C/C++. It’s a skill I’m sure I could build, but it’s not going to be pretty at first.
- memling 4y agoEducate me, pkease: why no new or delete? Does C++ now discourage heap allocation or is the common practice to use smart pointers, etc.?
- thrwyoilarticle 4y agoConstructing into a unique_ptr[1] will mean you don't have to risk forgetting to delete it or risk managing something you don't own. You'll also sometimes get compiler spew that you'll learn is telling you you're trying to do something nonsensical e.g. use its copy ctor. In contrast, if you try to copy a raw pointer that is intended to be unique then you get a copy of a pointer and a Heisenbug. Also a lot can be done with things that are on the heap but act as local variables. [1] You probably don't actually need a shared_ptr and if you do then it won't stop you from creating memory leaks.
- underdeserver 4y agoYep. In new code you should use smart pointers for allocation as much as you can.