Smart pointer template for managing dynamically allocated memory
#ifndef SMARTPTR_HPP#define SMARTPTR_HPP #include
template
class SmartPtr{ public: SmartPtr(T *type = NULL); void resetPtr(T *type); const T *getPtr()const; operator bool() const{ return ptr_ == NULL; } ~SmartPtr(); T &operator*(); const T &operator*()const; T *operator->(); const T *operator->()const; private: SmartPtr(const SmartPtr &); void operator=(const SmartPtr &); T *ptr_;};template
inline SmartPtr
::SmartPtr(T *type) :ptr_(type){}template
inline void SmartPtr
::resetPtr(T *type){ if(ptr_ != type){ if(ptr_ != NULL){ delete ptr_; } ptr_ = type; }}template
inline const T *SmartPtr
::getPtr() const{ return ptr_;}template
inline SmartPtr
::~SmartPtr(){ if(ptr_ != NULL){ delete ptr_; }}template
inline T &SmartPtr
::operator*(){ return *ptr_;}template
inline const T &SmartPtr
::operator*() const{ return *ptr_;}template
inline T *SmartPtr
::operator->(){ return ptr_;}template
inline const T *SmartPtr
::operator->() const{ return ptr_;}#endif /*SMARTPTR_H*/