|
|
在BREW里实现智能指针Smart Port[初级] |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
template<class T> class CTJBrewPtr { public: typedef T element_type; //ctor explicit CTJBrewPtr(T *pVal = 0) throw() { if(pVal) m_AutoPtr = pVal; else m_AutoPtr = NULL; i = 0; } //copy ctor CTJBrewPtr(const CTJBrewPtr<T>& ptrCopy) throw() { if(ptrCopy) m_AutoPtr = ptrCopy; else m_AutoPtr = NULL; i = 0; } //overloading = operator CTJBrewPtr<T>& operator=(CTJBrewPtr<T>& ptrCopy) throw() { if(ptrCopy) m_AutoPtr = &ptrCopy; else m_AutoPtr = 0; return m_AutoPtr; } //dtor ~CTJBrewPtr() { if(m_AutoPtr) { delete m_AutoPtr; } } //overloading * operator T& operator*() const throw() { return *m_AutoPtr; } //overloading -> operator T *operator->() const throw() { return m_AutoPtr; } //function to get the pointer to the class T *get() const throw() { return m_AutoPtr; } private: T *m_AutoPtr; uint32 i; };
|
|
相关文章:相关软件: |
|