1
votes

In my project, before I upgraded to VS2015, it compiled just fine. Now I'm getting 10 errors that have to do with std::chrono::timepoint. These are all the errors: https://gyazo.com/0d3c51cf87c49661b0f24da4a027b0d9 (image since there's so many)

Example lines of code that cause errors:

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

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

causes

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

(fStart is a chrono::system_clock::timepoint, t is a double obviously)

Here is the full function those errors are from if someone wants to see it:

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();
        }
    }
}

What am I supposed to do to fix these?

1
How are we supposed to know, if you don't tell us what fStart is? :) - melak47
In general, a minimal, reproducible example would be immensely helpful. - melak47
std::chrono::time_point is a template. time_points from different clocks are not necessarily convertible. We need to know the actual type. - melak47
Then that's your problem. You can't store a high_resolution_clock::time_point in a system_clock::time_point - melak47
See [std::chrono::high_resolution_clock] may be an alias of std::chrono::system_clock or std::chrono::steady_clock, or a third, independent clock. here - melak47

1 Answers

1
votes

I recommend abandoning use of std::chrono::high_resolution_clock.

If you need a time_point that has to be stable across processor runs, or processes, use std::chrono::system_clock, which has a definitive relationship to the civil calendar.

Otherwise use std::chrono::steady_clock. This clock is like a stopwatch. It is good for timing stuff, but it can't tell you the current (civil) time.