Template simulates a "smart" pointer which deletes the item it is pointing to when no more references to the item exist
class A {
Template simulates a "smart" pointer which deletes the item it is pointing to when no more references to the item exist. Warning: circular references will produce memory leaks.Note that only one Sptr should be constructed from the original ptr -- Sptr will free twice (and cause havoc) if it is misused like so:
WRONG:
T* obj = new T(); Sptrp; Sptr q; p = obj; q = obj; now both p and q think they are the only ones who will free the memory, so you will get an error.
void decrement()
template < class T2 > operator Sptr
template < class T2 > operator const Sptr
Sptr()
Sptr(T* original, int* myCount = 0, VMutex* myMutex = 0)
Sptr(const Sptr& x)
~Sptr()
T& operator*()
int operator!()
T* operator->()
template < class T2 > Sptr& dynamicCast(const Sptr < T2 > & x)
class A {
...
};
class B : public A {
...
};
class C {
...
};
...
int main()
{
Sptr< A > a;
Sptr< B > b;
Sptr< C > c;
a = new B;
b.dynamicCast(a);
c.dynamicCast(a);
}
template < class T2 > Sptr& operator=(const Sptr < T2 > & x)
Sptr& operator=(T* original)
Sptr& operator=(const Sptr& x)
friend int operator!=(const void* y, const Sptr& x)
friend int operator!=(const Sptr& x, const void* y)
friend int operator==(const void* y, const Sptr& x)
friend int operator==(const Sptr& x, const void* y)
int operator==(const Sptr& x)
int operator!=(const Sptr& x)
VMutex* getMutex()
int* getCount()
T* getPtr()
generated by doc++