12345678910111213
template < typename T > struct instance_counted // base class { instance_counted() noexcept { ++instance_cnt ; } ~instance_counted() noexcept { --instance_cnt ; } instance_counted( const instance_counted& ) noexcept : instance_counted() {} instance_counted( instance_counted&& ) noexcept : instance_counted() {} instance_counted& operator= ( const instance_counted& ) noexcept { return *this; } instance_counted& operator= ( instance_counted&& ) noexcept { return *this; } static int instance_cnt ; }; template < typename T > int instance_counted<T>::instance_cnt = 0 ;
struct A : instance_counted<A> { /* ... */ };