Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何修复C+中std::chrono比较的编译错误+;11?_C++_C++11_Boost Asio_Chrono - Fatal编程技术网

C++ 如何修复C+中std::chrono比较的编译错误+;11?

C++ 如何修复C+中std::chrono比较的编译错误+;11?,c++,c++11,boost-asio,chrono,C++,C++11,Boost Asio,Chrono,我遵循这个示例,这里显示的line at函数从deadline\u timer::traits\u type::now()修改为std::chrono::stable\u clock::now(),因为我想使用独立的ASIO而不使用boost。ASIO可以与C++11一起使用单机版 void check_deadline(deadline_timer* deadline) { if (stopped()) return; // Check whether the d

我遵循这个示例,这里显示的line at函数从deadline\u timer::traits\u type::now()修改为std::chrono::stable\u clock::now(),因为我想使用独立的ASIO而不使用boost。ASIO可以与C++11一起使用单机版

void check_deadline(deadline_timer* deadline)
{
    if (stopped())
      return;

    // Check whether the deadline has passed. compare the deadline against
    // the current time 
    // I modified this to be std::chrono::steady_clock::now()
    if (deadline->expires_at() <= deadline_timer::traits_type::now())         {
      // deadline is asio::high_resolution_time type
      stop();
    } else {
      // Put the actor back to sleep.
      deadline->async_wait(
          std::bind(&TCP_Session::check_deadline, shared_from_this(), deadline));    
    }
  }
无效检查\u截止日期(截止日期\u计时器*截止日期)
{
if(stopped())
返回;
//检查截止日期是否已过。将截止日期与
//当前时间
//我将其修改为std::chrono::staid_clock::now()
如果(截止日期->到期时间为()异步等待(
std::bind(&TCP_Session::check_deadline,shared_from_this(),deadline));
}
}
问题 在VS2015中,编译工作正常,但在EclipseG++4.9.2中,它抱怨

no match for 'operator<=' (operand types are 
'asio::basic_waitable_timer<std::chrono::_V2::system_clock>::time_point 

aka 
std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long long int, std::ratio<1ll, 1000000000ll> > >}'

 and 

'std::chrono::_V2::steady_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long long int, std::ratio<1ll, 1000000000ll> > >}')  TCPSession.h    line 284    C/C++ Problem

no match for'operatorBoost Asio是否使用
std::chrono
取决于预处理器定义(或者定义取决于检测到的编译器,我不记得了)

我记得,没有这种依赖关系的计时器应该是
asio::high_resolution\u timer
。只要确保使用了正确的时钟和计时器组合即可

在我看来,您也应该验证名为
deadline
的变量的实际类型。

不幸的是,没有定义要匹配的
deadline timer
。但是,我认为您会发现
asio::stable\u timer
应该可以工作

我使用以下宏在“standalone”和“boost”之间切换:

#ifdef ASIO_STANDALONE
  #include <asio.hpp>
  #define ASIO asio
  #define ASIO_ERROR_CODE asio::error_code
  #define ASIO_TIMER asio::steady_timer
#else
  #include <boost/asio.hpp>
  #define ASIO boost::asio
  #define ASIO_ERROR_CODE boost::system::error_code
  #define ASIO_TIMER boost::asio::deadline_timer
#endif
#ifdef ASIO#u独立
#包括
#定义ASIO ASIO
#定义ASIO\U错误\U代码ASIO::错误\U代码
#定义ASIO\U计时器ASIO::稳定\U计时器
#否则
#包括
#定义ASIO boost::ASIO
#定义ASIO\U错误代码boost::system::ERROR\U代码
#定义ASIO_定时器boost::ASIO::deadline_定时器
#恩迪夫

嗯,其中一个来自
系统时钟
,另一个来自
稳定时钟
。它们是不同的时钟。“不幸的是,独立ASIO没有定义一个截止时间计时器来匹配升压ASIO。”嗯,那是什么呢?@T.C.记录了一些不存在的东西。虽然
asio 1.10.6
有一个
basic\u-deadline\u-timer.hpp
文件,但它实际上没有定义
deadline\u-timer
,请参阅:以获取解释。