C++: Difference between revisions

162 bytes added ,  18 October 2019
Line 100: Line 100:
Use <code>shared_ptr</code> when multiple objects need to reference the same thing.<br>
Use <code>shared_ptr</code> when multiple objects need to reference the same thing.<br>
Use <code>weak_ptr</code> to avoid cyclic dependencies which cause issues with reference counting.<br>
Use <code>weak_ptr</code> to avoid cyclic dependencies which cause issues with reference counting.<br>
Example:
<syntaxhighlight lang="cpp">
std::unique_ptr<Car> my_car(new Car());
// Or starting from C++14
auto my_car = std::make_unique<Car>();
</syntaxhighlight>


====Garbage Collection====
====Garbage Collection====