如何使用 chrono return 持续时间类型

How to return a duration type using chrono

我正在编写一个 class 函数,它使用 chrono 库 returns 以微秒为单位的持续时间。

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

出于某种原因,我的编译器向我吐了。感谢所有帮助!

std::chrono::microseconds
stop_watch::get_time()
{
   using namespace std::chrono;
   return duration_cast<microseconds>(stop_time - start_time);
}