#ifndef COUNTEDH #define COUNTEDH #include #include using namespace std; class counted { static unsigned _count; int i; public: counted(int initial_i) {i = initial_i; ++_count;} counted(const counted& another) {i = another.i; ++_count;} ~counted() {--_count;} friend bool equal(const counted& c1, const counted& c2) { assert(_count > 0); return c1.i == c2.i; } friend int average(const counted& c1, const counted& c2); static unsigned count() {return _count;} //Return true if any counted objects currently exist. static bool exist() {return _count > 0;} void print() const { assert(_count > 0); cout << i; } }; inline int average(const counted& c1, const counted& c2) { assert(counted::_count > 0); return (c1.i + c2.i) / 2; } #endif