In this recipe, we will learn how to convert from a std::unique_ptr into a std::shared_ptr. This recipe is important as it is often convenient to define an API as accepting std::unique_ptr when the API itself really needs std::shared_ptr for internal use. A good example of this is when creating a GUI API. You might pass a widget to the API to store and own, without knowing if, later on down the road, the implementation of your GUI might need to add threads, in which case std::shared_pointer might be a better option. This recipe will provide you with the skills to convert a std::unique_ptr into a std::shared_ptr if needed, without having to modify the API itself.
United States
Great Britain
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Singapore
Hungary
Philippines
Mexico
Thailand
Ukraine
Luxembourg
Estonia
Lithuania
Norway
Chile
South Korea
Ecuador
Colombia
Taiwan
Switzerland
Indonesia
Cyprus
Denmark
Finland
Poland
Malta
Czechia
New Zealand
Austria
Turkey
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Malaysia
South Africa
Netherlands
Bulgaria
Latvia
Japan
Slovakia