4 ms·
Ironically, this post suffers from excessive C'ism and older-C++'ism. Specifically, it encourages the use of pointers for passing-by-reference, and when workin
by einpoklum 2y ago
Ironically, this post suffers from excessive C'ism and older-C++'ism.
Specifically, it encourages the use of pointers for passing-by-reference, and when working with class hierarchies. This is inappropriate and overly dangerous; and references (especially const references) should be prefered, or passing-by-value (and utlilization of copy elisions).
The post also suggests people perform raw allocations with `new`. That is also discouraged; see C++ Core Guideline R11. [1]
[1]: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r11-avoid-calling-new-and-delete-explicitly https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines...
- williamcotton 2y ago> Next Up: Smart Pointers > RAII is a powerful technique but what we've seen so far is only a partial solution. Things are (mostly) fine when working with objects but if we want to work with pointers, as in our Rectangle example, then we need to implement custom copy constructors, copy assignment operators, etc. if we want them to be safe. This is true even if we want to store on object on the heap but have a pointer on the stack. In the next post I'll be covering a technique called "smart pointers" that helps address these problems.
- ekr____ 2y agoAuthor here. As the comment below suggests, I'm building my way up to smart pointers, so that requires doing some suboptimal things along the way. I'm trying to make clear that they're suboptimal as I go, without getting too deep into the weeds, but it's a bit of a balance.