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

[more]bool res

Public Methods

[more] SmartPtr(void)
Default constructor
[more] SmartPtr(T* ptr)
Constructor based on a pointer to the desired object After this call, the pointer is under control !
[more] ~SmartPtr(void)
Destructor : free a reference of the counted object If the references counter == 0, free the object
[more] SmartPtr(SmartPtr<T> const & ref)
Copy-constructor : get a new reference to the counted object
[more]SmartPtr<T> & operator=(SmartPtr<T> const &ref)
Assignment operator : release the current counted object and get a new reference to the counted object
[more]T* operator->()
Dereferencement operator : provide consistent use of counted objects obj->member_of_class_T even if obj is in fact SmartPtr<T> obj;
[more]T const* operator->() const
Const dereferencement operator
[more]T* getPtr(void) const
Returns the pointer, without any control
[more] return(lhs==rhs)
[more]bool Null(void) const
true if the SmartPtr object does not reference any pointer
[more]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
o SmartPtr(void)
Default constructor

o SmartPtr(T* ptr)
Constructor based on a pointer to the desired object After this call, the pointer is under control !

o ~SmartPtr(void)
Destructor : free a reference of the counted object If the references counter == 0, free the object

o SmartPtr(SmartPtr<T> const & ref)
Copy-constructor : get a new reference to the counted object

oSmartPtr<T> & operator=(SmartPtr<T> const &ref)
Assignment operator : release the current counted object and get a new reference to the counted object

oT* operator->()
Dereferencement operator : provide consistent use of counted objects obj->member_of_class_T even if obj is in fact SmartPtr<T> obj;

oT const* operator->() const
Const dereferencement operator

oT* 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 :(

obool res

o return(lhs==rhs)

obool Null(void) const
true if the SmartPtr object does not reference any pointer

ovoid 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++.