![]() |
A std::shared_pointer is a smart pointer introduced in C++11 that manages the lifetime of a dynamically allocated object through reference counting. In this article, we will learn how to create a shared_pointer. shared_ptr in C++A std::shared_pointer can be created by using the std::make_shared method which is defined in <memory> header in C++. Use the below syntax to create a shared_ptr. Syntax to Create shared_ptr in C++auto sharedPtr = make_shared<Type>(constructor_arguments); Here,
C++ Program to Create shared_ptrThe below demonstrates how we can create a shared_ptr using the make_shared function and then access a member function of the class. C++
Output
MyClass Constructor Hello! MyClass Destructor
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |