Hacker News new | ask | show | jobs
by dmitrykoval 1857 days ago
For this particular example direct initialization i.e. std::string product("not worked"); would be preferred, as you end up using one call to constructor instead of two: default constructor followed by the move assignment.

https://en.cppreference.com/w/cpp/language/direct_initializa... https://en.cppreference.com/w/cpp/language/move_assignment

1 comments

Thank you very much.

What are examples of situations where the other pattern would be preferable?

afaik the only time you are really supposed to use uninitialized values is when you are planning on reading it in from some stream.

otherwise you should really avoid it.