gpt4 book ai didi

c++ - 错误太多 (std::chrono::timepoint) (VS2015)

转载 作者:行者123 更新时间:2023-11-30 05:34:22 24 4
gpt4 key购买 nike

在我的项目中,在我升级到 VS2015 之前,它编译得很好。现在我收到 10 个与 std::chrono::timepoint 有关的错误。这些都是错误:https://gyazo.com/0d3c51cf87c49661b0f24da4a027b0d9(图片太多了)

导致错误的示例代码行:

fStart = clock::now();原因no operator '=' matches these operands

double t = std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - fStart).count();

原因

no instance of function template 'std::chrono::duraction_cast' matches the argument list. argument types are: ( <error-type> )

(fStart 是一个 chrono::system_clock::timepoint,t 显然是一个 double)

如果有人想看的话,这里是这些错误的完整函数:

void Animation::update() {
using clock = std::chrono::high_resolution_clock;
if (animType == TYPE_MS) {
if (firstUpdate) {
fStart = clock::now();
firstUpdate = false;
}

double t = std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - fStart).count();

if (!paused) {
if (t >= frames[frame]->getTime())
advance();
}
} else if (animType == TYPE_FRAME) {
if (firstUpdate)
firstUpdate = false;

if (!paused)
fTime += speed;

if (speed < 0.0) {
if (fTime <= -frames[frame]->getTime())
advance();
} else {
if (fTime >= frames[frame]->getTime())
advance();
}
}
}

我应该怎么做才能解决这些问题?

最佳答案

我建议放弃使用 std::chrono::high_resolution_clock

如果您需要一个必须在处理器运行或进程之间保持稳定的 time_point,请使用 std::chrono::system_clock,它与民历。

否则使用 std::chrono::steady_clock。这个时钟就像一个秒表。它适用于计时,但不能告诉您当前(民用)时间。

关于c++ - <chrono> 错误太多 (std::chrono::timepoint) (VS2015),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34257225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com