top | item 46686282

(no title)

ranit | 1 month 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".

discuss

order

bulbar|1 month ago

Such 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".

jurschreuder|1 month ago

He'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