class Temp{ public: Temp(){ ++N; sum+=N; } static void Reset(){ N = 0; sum = 0; } static int getSum(){ return sum; } private: static int N; static int sum; }; int Temp::N = 0; int Temp::sum = 0; int sum(int n){ Temp::reset(); Temp * a = new Temp[n]; delete []a; return Temp::getSum(); }