jeudi 22 juin 2017

No match for "operator =" when using std::chrono::high_resolution_clock

when I compiled this timer.hpp header file below, The compiler said error: no match for ‘operator=’ (operand types are ‘std::chrono::_V2::system_clock::time_point {aka std::chrono::time_point > >}’ and ‘std::__success_type > >::type {aka std::chrono::duration >}’) end = std::chrono::high_resolution_clock::now() - start;

I guess the variable type for start and end is wrong. What is the correct type? I want to use std::chrono::high_resolution_clock.

#include <chrono>

namespace timer{
static std::chrono::system_clock::time_point start, end;

void initTime(){
    start = std::chrono::high_resolution_clock::now();
}


void endTime(){
    end = std::chrono::high_resolution_clock::now() - start;
}

}

timer.hpp is supposed to be used with some main file. By calling timer::initTime() before some function that I want to measure and calling timer::endTime() after the function, I would get the timing result ( the getter for the duration time is omitted here).

Aucun commentaire:

Enregistrer un commentaire