所以,我的代码没有编译,但我很想编译。这是我的代码:
float numSeconds = 50;
std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();
auto duration = std::chrono::duration<float, std::chrono::seconds>(numSeconds);
startTime -= duration;
看起来应该很简单,但在尝试就地减法时,我遇到了一个运算符未找到的错误。有什么建议吗?我还尝试将第三行替换为以下内容:
auto duration = std::chrono::duration<float, std::ratio<1, 1>>(numSeconds);
然而,这条线似乎不是问题的原因,这两种方法似乎都是有效的。我最后一句话还是不开心。
编辑:我发布的原始代码中有一个拼写错误,所以大多数答案与我的实际问题无关。我得到的错误代码在最后一行:
"Error C2679 binary '-=': no operator found which takes a right-hand operand of type 'std::chrono::duration<float,std::chrono::seconds>' (or there is no acceptable conversion)"
此外,当我将最后一行更改为:
timer.m_startTime = timer.m_startTime - duration;
我得到以下错误代码:
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::chrono::time_point<std::chrono::steady_clock,std::chrono::duration<float,std::ratio<1,1000000000>>>' (or there is no acceptable conversion)