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
United Kingdom
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Argentina
Austria
Belgium
Bulgaria
Chile
Colombia
Cyprus
Czechia
Denmark
Ecuador
Egypt
Estonia
Finland
Greece
Hungary
Indonesia
Ireland
Italy
Japan
Latvia
Lithuania
Luxembourg
Malaysia
Malta
Mexico
Netherlands
New Zealand
Norway
Philippines
Poland
Portugal
Romania
Singapore
Slovakia
Slovenia
South Africa
South Korea
Sweden
Switzerland
Taiwan
Thailand
Turkey
Ukraine