当我低于此timer.hpp头文件进行编译时找不到符合“运营商=”, 编译器说 错误:不对应的“操作符=”(操作数类型是'std :: chrono :: _ V2 :: system_clock :: time_point {aka std :: chrono :: time_point >>}'和'std :: __ success_type>> :: type {aka std :: chrono :: duration>} ') end = std :: chrono :: high_resolution_clock :: now() - start;使用std ::时辰:: high_resolution_clock
我猜测开始和结束的变量类型是错误的。 什么是正确的类型? 我想使用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应该包含一些重要的文件中使用。通过在函数之后调用timer :: initTime()函数之前调用timer :: endTime()函数之前,我会得到计时结果(持续时间的getter在这里省略)。
以下是'chrono'视频教程:https://www.youtube.com/watch?v=P32hvk8b13M它解决了这些问题。 –