面接問題46 1+2+3+...+n
1888 ワード
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();
}