65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
size_t count_calls(){
static size_t ctr = 0;
return ++ctr;
}
void main(void){
for (size_t i = 0; i != 10; ++i)
cout << count_calls() << endl;
system("pause");
}
static size_t ctr = 0;
不是赋值,而是一个带初始化的声明
static变量的初始化只进行一次