SmartPointer<T>::SmartPointer (T *t) :
t (t)
{
- if (t)
+ if (t != 0)
t->subscribe();
};
SmartPointer<T>::SmartPointer (const SmartPointer<T> &tt) :
t (tt.t)
{
- if (t)
+ if (t != 0)
t->subscribe();
};
template <typename T>
SmartPointer<T>::~SmartPointer ()
{
- if (t)
+ if (t != 0)
t->unsubscribe();
};
if (t == tt)
return *this;
- if (t)
+ if (t != 0)
t->unsubscribe();
t = tt;
- if (tt)
+ if (tt != 0)
tt->subscribe();
return *this;
};
if (&tt == this)
return *this;
- if (t)
+ if (t != 0)
t->unsubscribe();
t = static_cast<T*>(tt);
- if (tt)
+ if (tt != 0)
tt->subscribe();
return *this;
};
inline
void SmartPointer<T>::swap (T *&tt)
{
- t->unsubscribe ();
+ if (t != 0)
+ t->unsubscribe ();
+
std::swap (t, tt);
- t->subscribe ();
+
+ if (t != 0)
+ t->subscribe ();
};
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams