//: C09:Countable.h // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // A "mixin" class. #ifndef COUNTABLE_H #define COUNTABLE_H #include class Countable { long count; protected: Countable() { count = 0; } virtual ~Countable() { assert(count == 0); } public: long attach() { return ++count; } long detach() { return (--count > 0) ? count : (delete this, 0); } long refCount() const { return count; } }; #endif // COUNTABLE_H ///:~