![]() |
std::make_unique is a utility function in C++ that was introduced in C++14. It is used to create a unique_ptr object, which is a smart pointer that manages the lifetime of dynamically allocated objects. It is defined inside <memory> header file. Syntaxstd::make_unique <object_type> (arguments); Parameters
Return Type
It is the preferred way to create a std::unique_ptr, as it is safer than using the new operator directly because the object is automatically destroyed when it goes out of scope. Examples of std::make_uniqueThe following programs demonstrate how to implement std::make_unique() in our programs. Example 1C++
Output
Object Created Object Destroyed Example 2C++14
Output
Object Created 10 Object Destroyed Advantages of std::make_unique
|
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |