6.1.1 局部对象-局部静态对象

书中页数:P185
代码名称:count-calls.cc

#include <cstddef>
using std::size_t;

#include <iostream>
using std::cout; using std::endl;

size_t count_calls()
{
	static size_t ctr = 0;  // value will persist across calls
	return ++ctr;
}

int main() 
{
	for (size_t i = 0; i != 10; ++i)
		cout << count_calls() << endl;
	return 0;
}
上一篇:[LeetCode 1558] Minimum Numbers of Function Calls to Make Target Array


下一篇:使用ThreadPoolExecutor 创建线程池,完成并行操作