Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return a duration type using chrono

Tags:

c++

c++-chrono

I am writing a class function that returns a duration in microseconds using the chrono library.

std::chrono::duration<std::chrono::miroseconds> stop_watch::get_time() {
   auto length = std::chrono::duration_cast<std::chrono::microseconds>(stop_time - start_time);
   return length;
}

For some reason my compiler is throwing up at me. All help appreciated thanks!

like image 339
Swluo Avatar asked Nov 22 '25 12:11

Swluo


1 Answers

std::chrono::microseconds
stop_watch::get_time()
{
   using namespace std::chrono;
   return duration_cast<microseconds>(stop_time - start_time);
}
like image 142
Howard Hinnant Avatar answered Nov 24 '25 02:11

Howard Hinnant