See Object counter example here: Why it just does not inherit from non-template class counter
. Why counter should be template?
template <typename T>
struct counter
Specializations will give you different counter
s for different types.
Note that those counters are static data members, thus shared among all instances of the given specialization.