求助
  • 板块灌水区
  • 楼主_LogicFish_
  • 当前回复3
  • 已保存回复3
  • 发布时间2025/1/18 09:59
  • 上次更新2025/1/18 13:25:21
查看原帖
求助
862827
_LogicFish_楼主2025/1/18 09:59

这是一段用于计时的C++代码(C++11)

struct Stopwatch{
	Stopwatch(chrono::nanoseconds& _res)
	:res{_res},
	 start{chrono::high_resolution_clock::now()} {}
	~Stopwatch()
	{
		res=chrono::high_resolution_clock::now()-start;
	}
	private:
		chrono::nanoseconds& res;
		chrono::time_point<chrono::high_resolution_clock> start;
};

报错了:
line 4: [Error] invalid initialization of non-const reference of type 'std::chrono::nanoseconds& {aka std::chrono::duration<long long int, std::ratio<1ll, 1000000000ll> >&}' from an rvalue of type '<brace-enclosed initializer list>'
所以怎么办

2025/1/18 09:59
加载中...