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.
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