- Use boost::unique_ptr:
#include
class MyClass { private: boost::unique_ptr m_ptr; }; - Conditionally use auto_ptr or unique_ptr:
#if __cplusplus < 201103L #include
#else #include #endif class MyClass { private: #if __cplusplus < 201103L std::auto_ptr m_ptr; #else std::unique_ptr m_ptr; #endif }; - Use a preprocessor macro:
#define AUTO_PTR std::auto_ptr class MyClass { private: AUTO_PTR
m_ptr; }; Note that this macro approach is not recommended, as it can lead to subtle errors if you are not careful.
- Wrap the std:: smart pointer in your own defined template smart pointer class:
template
class MySmartPtr { private: std::unique_ptr m_ptr; public: MySmartPtr(T* ptr) : m_ptr(ptr) {} T* get() { return m_ptr.get(); } T* release() { return m_ptr.release(); } }; class MyClass { private: MySmartPtr m_ptr; };