/* * SPtr.cpp * * Created on: Oct 4, 2012 * Author: mike */ #include "SPtr.hpp" //------------------------------------------------------------------------------ // Make *this point to the same T object as p. void SPtr::attach(SPtr& p) { count = p.count; target = p.target; // copy pointer (*count)++; } //------------------------------------------------------------------------------ // Make *this no longer point to anything, and delete the count and target // if this was the last pointer to that object. void SPtr::detach() { if (*count == 1) { cout << "releasing SPtr" << endl; delete count; count = nullptr; delete target; target = nullptr; } else { (*count)--; } }