这是一段用于计时的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>'
所以怎么办