#pragma once template class scoped_ptr { public: scoped_ptr(T* ptr); scoped_ptr& operator=(T* lhs); T* operator->(); bool operator==(T* lhs); ~scoped_ptr(); T* operator *(); private: T* p; }; template scoped_ptr::scoped_ptr(T* ptr) :p(ptr) { } template scoped_ptr& scoped_ptr::operator=(T* lhs) { if (p != nullptr) { delete p; p = nullptr; } p = lhs; return *this; } template T* scoped_ptr::operator->() { return p; } template scoped_ptr::~scoped_ptr() { if (p != nullptr) { delete p; p = nullptr; } } template bool scoped_ptr::operator==(T* lhs) { return p == lhs; }