<chrono> 错误太多(std::chrono::timepoint)(VS2015)

Too many <chrono> errors (std::chrono::timepoint) (VS2015)

在我的项目中,在我升级到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。这个时钟就像一个秒表。它对计时很有用,但它不能告诉你当前的(民用)时间。