Synopsis: | In case allocated memory has to be deallocated later by someone else, use a unique_ptr with move semantics |
Language: | C++ |
Severity Level: | 1 |
Category: | Object Allocation |
Description: |
Example: std::unique_ptr<Foo> createFoo() { std::unique_ptr<Foo> ptr(new Foo); // return unique pointer to Foo return ptr; } void m() { auto foo = createFoo(); // transfer ownership of foo to bar Bar bar(std::move(foo)); } |