Re:We used C++20 to eliminate a class of runtime bugs
by not2b on Friday January 14, 2022 @03:18PM
(#29939808)
The "best default" way of instantiating is
Foo foo(args);
Sometimes an object has to be on the heap as its own separate allocation (rather than on the stack or as a data member), but I notice that some new developers who come to C++ from some other language use the heap way too much.
Re:We used C++20 to eliminate a class of runtime bugs
by criddell on Friday January 14, 2022 @03:11PM
(#29939694)
> Think about explaining this to a new C++ developer.
How's this:
The code allocates and initializes a new Foo instance with args. By using make_unique you guarantee that the destructor is called when foo goes out of scope for any reason.
This will feel much more natural to most developers: