1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| /*
class const_dumb_ptr:
This class holds a pointer, but is NOT a smart pointer.
No destruction is performed on the pointer.
However, this class propagates const-ness to the pointer:
when a const_ptr object is const, it becomes a pointer to const object.
This class is best used for declaring class member variables, but remember
the containing class must not manage the lifetime of more than one resource
This class is entirely implemented inline.
*/
template< class T >
class const_dumb_ptr
{
public:
typedef T elem_type;
private:
elem_type * m_ptr;
public:
//const_dumb_ptr() {} //No default constructor: Compiler will refuse uninitialized
const_dumb_ptr(elem_type *ptr) : m_ptr(ptr) {}
elem_type * operator-> ()
{ return m_ptr; }
elem_type const * operator-> () const
{ return m_ptr; }
operator elem_type* ()
{ return m_ptr; }
operator elem_type const* () const
{ return m_ptr; }
elem_type ** operator& ()
{ return &m_ptr; }
}; |
Partager