7 ms·
> I don't know why people use 'new' and 'delete' in all the examples ... Why? Because the blog post is titled "Understanding C++ Ownership System".
by ranit 8mo ago
> I don't know why people use 'new' and 'delete' in all the examples ...
Why? Because the blog post is titled "Understanding C++ Ownership System".
- jurschreuder 8mo agoHe's making it massively more complex than it actually is { // this scope is owner // allocate auto my_obj = MyObj{}; // this function scope does not have ownership of my_obj, should take (const MyObj& obj) const reference as parameter do_something(my_obj); } // memory is released
- bulbar 8mo agoSuch article can end up with a 'false balance' bias by introducing and showing a method one should avoid to motivate the solution. What some people learn is "there are two options". Maybe it works be better to start with "that's how we do it" and only afterwards following up with "and that's why".