我昨天问了这个问题,但是我的帖子被关闭了,所以我在说空话。所以,我的代码无法编译,但我非常希望它能够编译。这是我的片段:
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;
Run Code Online (Sandbox Code Playgroud)
看起来应该非常简单,但在尝试就地减法时,我收到了“未找到运算符”错误。有什么建议么?我还尝试用以下内容替换第三行:
auto duration = std::chrono::duration<float, std::ratio<1, 1>>(numSeconds);
Run Code Online (Sandbox Code Playgroud)
然而,这条线似乎并不是问题的原因,两种方法似乎都是有效的。这是我的最后一句话,但仍然不满意。我收到的错误代码是:
"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)"
Run Code Online (Sandbox Code Playgroud)
另外,当我将最后一行更改为:
timer.m_startTime = timer.m_startTime - duration;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误代码:
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)
Run Code Online (Sandbox Code Playgroud)
这些类型是否不兼容?我认为他们会决心做同样的事情。