C++ examples for Data Type:unique_ptr
Using unique_ptr Managed Pointers to automate memory managing in your C++ programs.
#include <iostream> #include <memory> using namespace std; class MyClass/*from w w w.j av a 2 s . c om*/ { private: int m_Value{ 10 }; public: MyClass() { cout << "Constructing!" << endl; } ~MyClass() { cout << "Destructing!" << endl; } int GetValue() const { return m_Value; } }; int main() { unique_ptr<MyClass> uniquePointer{ make_unique<MyClass>() }; cout << uniquePointer->GetValue() << endl; return 0; }