// I have not implemented/tested this code. // There are most likely errors. // This is for conversation. template <typename T> class UniquePointerT { public: UniquePointerT(): data{new T} { } UniquePointerT(const UniquePointerT & other) { // copy it allocating new data. } UniquePointerT & operator =(const UniquePointerT & other)=delete; ~UniquePointerT() { delete data; } private: T * data; }
memory
unique_ptr
unique_ptr<type> var; // a pointer to a single item unique_ptr<type[]> var; // a pointer to an array.
make_unique
data = make_unique<int>(); data1 = make_unique<int>(7); data2 = make_unique<int[]>(size);
get
gets the underlying pointer.