#include "RobotPtr.h" // this function releases the Robot pointer void RobotPtr::release() { if( --*counter == 0){ // we need to destroy the Robot object because there is no more pointers // pointing at the object delete ptr; delete counter; } } RobotPtr& RobotPtr::operator=(const RobotPtr& p) { if( this != &p ){ // we don't need to assign an object to itself release(); ptr = p.ptr; counter = p.counter; ++*counter; // don't forget to increment the counter because now // we have one more object ponting to it } return *this; }