c++ 11中的std::chrono::high_resolution_clock::now()是什么类型?

What is the type of std::chrono::high_resolution_clock::now() in C++11?

本文关键字:now 是什么 类型 clock resolution std chrono high c++ 中的      更新时间:2023-10-16

我需要在一个类中声明以下变量:

auto gameStartClock = std::chrono::high_resolution_clock::now();

然而,每当我尝试这样做时,我都会从gcc 5.1.0(启用c++ 11)收到此错误消息:

<file>.hpp:274: error: non-static data member declared 'auto'
auto gameStartClock = std::chrono::high_resolution_clock::now();                                                               ^
non-static data member declared 'auto'

所以我猜错误将消失后,我用正确的类型替换auto。然而,我在那里找到的关于::now()的每个例子都使用auto

它的类型是什么?

注意:我尝试了std::chrono::time_point与一些模板,但没有成功。不知道哪个是正确的

字体为std::chrono::time_point<std::chrono::high_resolution_clock>

从手册:http://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now

Edit:正如Lightness Races in Orbit在评论中指出的那样,您也可以使用std::chrono::high_resolution_clock::time_point