logoalt Hacker News

ranittoday at 12:01 AM2 repliesview on HN

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


Replies

bulbartoday at 6:08 AM

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

jurschreudertoday at 5:17 AM

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