template<class T> class SmartPtr
reference counted objects implementation used to handle instances in containers (like vectors) motivated by Mumit's STL Newbie guide inspired by David Harvey
Public Fields
-
bool res
Public Methods
-
SmartPtr(void)
- Default constructor
-
SmartPtr(T* ptr)
- Constructor based on a pointer to the desired object After this call, the pointer is under control !
-
~SmartPtr(void)
- Destructor : free a reference of the counted object If the references counter == 0, free the object
-
SmartPtr(SmartPtr<T> const & ref)
- Copy-constructor : get a new reference to the counted object
-
SmartPtr<T> & operator=(SmartPtr<T> const &ref)
- Assignment operator : release the current counted object and get a new reference to the counted object
-
T* operator->()
- Dereferencement operator : provide consistent use of counted objects obj->member_of_class_T even if obj is in fact SmartPtr<T> obj;
-
T const* operator->() const
- Const dereferencement operator
-
T* getPtr(void) const
- Returns the pointer, without any control
-
return(lhs==rhs)
-
bool Null(void) const
- true if the SmartPtr object does not reference any pointer
-
void setNull(void)
- frees the referenced pointer
Documentation
reference counted objects implementation used to handle instances in containers (like vectors) motivated by Mumit's STL Newbie guide inspired by David Harvey
- SmartPtr(void)
- Default constructor
- SmartPtr(T* ptr)
- Constructor based on a pointer to the desired object
After this call, the pointer is under control !
- ~SmartPtr(void)
- Destructor : free a reference of the counted object
If the references counter == 0, free the object
- SmartPtr(SmartPtr<T> const & ref)
- Copy-constructor : get a new reference to the counted object
- SmartPtr<T> & operator=(SmartPtr<T> const &ref)
- Assignment operator : release the current counted object
and get a new reference to the counted object
- T* operator->()
- Dereferencement operator : provide consistent use of counted objects
obj->member_of_class_T even if obj is in fact SmartPtr<T> obj;
- T const* operator->() const
- Const dereferencement operator
- T* getPtr(void) const
- Returns the pointer, without any control
Returns the pointer, without any control.
Warning : the following sequence may lead to segfault !
AClass * my_new_ptr = new AClass();
SmartPtr<AClass> reference_counted_object = new SmartPtr<my_new_ptr>;
...
AClass * my_ptr = reference_counted_object.getPtr();
delete my_ptr; freeing memory of a counted pointer ! ARGHHHH !
reference_counted_object->member(); SEGFAULT :(
- bool res
- return(lhs==rhs)
- bool Null(void) const
- true if the SmartPtr object does not reference any pointer
- void setNull(void)
- frees the referenced pointer
- This class has no child classes.
- Friends:
- bool operator==(SmartPtr<T> const & lhs, SmartPtr<T> const & rhs)
bool operator==(SmartPtr<T> const & lhs, std::string const & r_id)
bool operator==(SmartPtr<T> const & lhs, int value)
bool operator!=(SmartPtr<T> const & lhs, SmartPtr<T> const & rhs)
Alphabetic index HTML hierarchy of classes or Java
This page was generated with the help of DOC++.