class CBase {
 unsigned& (*Counter)();
public:
 CBase(unsigned& (*CountFunc)()) : Counter(CountFunc) {Counter()++;}
 ~CBase() {Counter()--;}
 unsigned get_count() {return Counter();}
};

template<typename T> class CMiddle : public CBase {
 static unsigned Count;
 static unsigned& Counter() {return Count;}
public:
 CMiddle(unsigned& (*CountFunc)() = Counter) : CBase(CountFunc) {}
};
class CDerivedA: public CMiddle<CDerivedA> {};
class CDerivedB: public CMiddle<CDerivedB> {};

//-------
template<typename T> unsigned CMiddle<T>::Count;

int main()
{
 CBase *pBase;
 CDerivedA a1, a2;
 CDerivedB b1, b2, b3;
 pBase = &a1;
 cout << pBase->get_count() << endl; // 結果: 2
 pBase = &b1;
 cout << pBase->get_count() << endl; // 結果: 3
}

こういうのはだめか?>>570