C++ examples for Data Type:shared_ptr
Creating a Shared Pointer
#include <iostream> #include <memory> using namespace std; class MyClass/*from w w w. j av a2 s .c o m*/ { private: int m_Number{ 0 }; public: MyClass(int value): m_Number{ value }{ } ~MyClass(){ cout << "Destroying " << m_Number << endl; } void operator=(const int value){ m_Number = value; } int GetNumber() const{ return m_Number; } }; using SharedMyClass = shared_ptr< MyClass >; int main(int argc, char* argv[]) { SharedMyClass sharedMyClass{ new MyClass(10) }; return 0; }