【发布时间】:2019-10-09 23:14:18
【问题描述】:
我正在编写 c++ 代码,我试图将 chrono time 保存在一个列表中,以便以后可以读取该值并计算持续时间。
在列表中保存时间的原因是因为我有多个对象,我需要捕获检测到该对象的当前时间,然后当该对象消失时,我必须计算该对象的持续时间.
list <double> dTimeList;
auto start = std::chrono::high_resolution_clock::now();
auto it = dTimeList.begin();
advance(it, detection.object_id);
dTimeList.insert(it, start ); //But this is giving error
错误(活动)E0304 重载函数“std::list<_ty _alloc>::insert [with _Ty=double, _Alloc=std::allocator]”的实例与参数列表不匹配
错误 C2664 'std::_List_iterator>> std::list<_ty>>::insert(std::_List_const_iterator>>,unsigned __int64,const _Ty &)': 无法转换参数2 从 'std::chrono::steady_clock::time_point' 到 '_Ty &&'
【问题讨论】:
-
dTimeList的类型是什么? -
@Holt 抱歉,我已经更新了类型。
-
您需要在列表中存储正确的类型,即
std::chrono::high_resolution_clock::time_point,而不是double。std::chrono::time_point不能隐式转换为数值类型,这是有充分理由的。