// File: scope_detector.cpp // Author: Chris Gill cdgill@cse.wustl.edu // Purpose: source file for memory management profiling classes // (See exercise 2 of the basic memory management studio) #include "stdafx.h" #include "scope_detector.h" // initialize static member unsigned int ScopeDetector::count_ = 0; // default constructor ScopeDetector::ScopeDetector () : i_ (count_++), ref_count_(0) { cout << "Default Constructing ScopeDetector with value " << i_ << endl; } // copy constructor ScopeDetector::ScopeDetector (const ScopeDetector &sd) : i_ (count_++), ref_count_(0) { cout << "Copy Constructing ScopeDetector with value " << i_ << " (from ScopeDetector with value " << sd.i_ << " )" << endl; } // destructor ScopeDetector::~ScopeDetector () { cout << "Destructing ScopeDetector with value " << i_ << endl; } // assignment operator ScopeDetector & ScopeDetector::operator= (const ScopeDetector &sd) { cout << "Assignment to ScopeDetector with value " << i_ << " (from ScopeDetector with value " << sd.i_ << ")" << endl; return *this; } // equivalence operator bool ScopeDetector::operator== (const ScopeDetector &sd) const { cout << "Equivalence comparison between ScopeDetector with value " << i_ << " and ScopeDetector with value " << sd.i_ << " (" << boolalpha << (i_ == sd.i_) << ") " << endl; return i_ == sd.i_; } // less than operator bool ScopeDetector::operator< (const ScopeDetector &sd) const { cout << "Less than comparison between ScopeDetector with value " << i_ << " and ScopeDetector with value " << sd.i_ << " (" << boolalpha << (i_ < sd.i_) << ") " << endl; return i_ < sd.i_; } // ostream insertion operator for ScopeDetector class ostream & operator << (ostream &os, const ScopeDetector &sd) { os << sd.i_; return os; }