是否可以使用std :: chrono :: duration与Rep类型为double?我得到编译器错误在vs2012当我尝试 [英] Is it possible to use std::chrono::duration with Rep type as double? I get compiler error in vs2012 when I try

查看:827
本文介绍了是否可以使用std :: chrono :: duration与Rep类型为double?我得到编译器错误在vs2012当我尝试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下编译器(vs2012)错误:

I get a following compiler (vs2012) error:


错误3错误C2679:binary'+ =':需要一个
类型的右侧操作数const std :: chrono :: duration< _Rep,_Period>'
(或没有可接受的转换)c:\program files
x86)\microsoft visual studio 11.0 \vc\include\chrono 749

Error 3 error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const std::chrono::duration<_Rep,_Period>' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono 749

我的持续时间定义是:

// Tick interval type in nanoseconds
typedef std::chrono::duration<double, std::ratio<1, 100000000>> tick_interval_type;

当我使用float ...时出现相同的错误...只有当持续时间的Rep类型为整数时,才会编译。

Same error when I use float... It only compiles when the Rep type of duration is integer.

有人可以帮忙吗?

编辑(输出中更完整的日志):

Edit (more complete log from Output):


c:\program files(x86)\microsoft visual studio
11.0 \vc\include\chrono(749):error C2679 :binary'+ =':无操作符,它接受类型为'const
std :: chrono :: duration< _Rep,_Period>'的右手操作数(或者没有可接受的
转换)与[
_Rep = double,
_Period = std :: nano] c:\program files(x86)\microsoft visual studio 11.0 \vc\include\chrono(166) be std :: chrono :: duration< _Rep,_Period>
& std :: chrono :: duration< _Rep,_Period> :: operator + =(const
std :: chrono :: duration< ;}尝试匹配参数列表(std :: chrono :: nanoseconds,const $ b)时,使用[
_Rep = __ int64,
_Period = std :: nano $ b std :: chrono :: duration< _Rep,_Period>)'与[
_Rep = double,
_Period = std :: nano] c:\program files(x86)\microsoft visual studio 11.0 \vc\include\thread(164):参见函数模板实例化xtime std :: _ To_xtime(const
std :: chrono :: duration< _Rep,_Period>&)编译时使用[
_Rep = double,
_Period = std :: nano] c:\dev\projects\revolverx\classes\ticker.h(78):参见函数模板实例化'void
std :: this_thread :: sleep_for(const
std :: chrono :: duration< _Rep,_Period>&)'用[
_Rep = double,
_Period = std :: nano]

c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(749): error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const std::chrono::duration<_Rep,_Period>' (or there is no acceptable conversion) with [ _Rep=double, _Period=std::nano ] c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(166): could be 'std::chrono::duration<_Rep,_Period> &std::chrono::duration<_Rep,_Period>::operator +=(const std::chrono::duration<_Rep,_Period> &)' with [ _Rep=__int64, _Period=std::nano ] while trying to match the argument list '(std::chrono::nanoseconds, const std::chrono::duration<_Rep,_Period>)' with [ _Rep=double, _Period=std::nano ] c:\program files (x86)\microsoft visual studio 11.0\vc\include\thread(164) : see reference to function template instantiation 'xtime std::_To_xtime(const std::chrono::duration<_Rep,_Period> &)' being compiled with [ _Rep=double, _Period=std::nano ] c:\dev\projects\revolverx\classes\ticker.h(78) : see reference to function template instantiation 'void std::this_thread::sleep_for(const std::chrono::duration<_Rep,_Period> &)' being compiled with [ _Rep=double, _Period=std::nano ]


推荐答案

chrono> 在Visual Studio中损坏。它不适用于混合型算术,这可能是主要功能之一< chrono> 。你得到这个错误,因为一方使用 __ int64 nanos和其他使用 double nanos。

<chrono> in Visual Studio is broken. It doesn't work with mixed type arithmetic, which, arguably, is one of the main features of <chrono>. You get this error because one of the sides uses __int64 nanos and the other uses double nanos.

我建议把它放在一个真正的C ++实现,或者使用Boost.Chrono。

I recommend either dropping it in favor of a real C++ implementation, or using Boost.Chrono.

这篇关于是否可以使用std :: chrono :: duration与Rep类型为double?我得到编译器错误在vs2012当我尝试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆