In the previous recipe, we've learned how to manage dynamic memory (allocated on the heap) in a very convenient way, by using unique_ptr. We've learned as well that unique_ptr must be used, just in case of exclusive ownership of the memory, or resources managed by the memory. But what if we have a resource that is co-owned by more entities? What if the memory we have to manage has to be released when all the owners have completed their job? Well, this is exactly the use case for shared_ptr. Just as with unique_ptr, for shared_ptr we don't have to allocate memory with new, but there is a template function (part of the C++ standard library), make_shared.
Germany
Slovakia
Canada
Brazil
Singapore
Hungary
Philippines
Mexico
Thailand
Ukraine
Luxembourg
Estonia
Lithuania
Norway
Chile
United States
Great Britain
India
Spain
South Korea
Ecuador
Colombia
Taiwan
Switzerland
Indonesia
Cyprus
Denmark
Finland
Poland
Malta
Czechia
New Zealand
Austria
Turkey
France
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Malaysia
South Africa
Netherlands
Bulgaria
Latvia
Australia
Japan
Russia