#include<iostream>
using namespace std;
class Temp
{
public:
Temp(){n++;sum += n;}
static int getsum() { return sum; }
private:
static int n;
static int sum;
};
//我们不能把静态成员的初始化放置在类的定义中,但是可以在类的外部通过使用范围解析运算符来对其进行初始化
int Temp::n = 0;
int Temp::sum = 0;
int sum_add(unsigned int n)
{
Temp* a = new Temp[n];
return Temp::getsum();
}
int main()
{
unsigned int data;
cout << "pls input a number:";
cin >> data;
int sum = sum_add(data);
cout << sum << endl;
}