【发布时间】:2019-01-06 22:07:44
【问题描述】:
我有一个利用 boost 库(1.58 版)的小型 C++ 项目,在调用 boost::asio::strand 时出现错误。我的语法似乎是错误的,但我不知道怎么做。
#pragma once
#ifndef TCPNETWORK_H_
#define TCPNETWORK_H_
//-----------------------------------------------------------------------------
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
#include <vector>
#include <list>
#include <boost/cstdint.hpp>
//-----------------------------------------------------------------------------
using boost::uint32_t;
using boost::uint16_t;
using boost::uint8_t;
using boost::int32_t;
using boost::int16_t;
using boost::int8_t;
//-----------------------------------------------------------------------------
class Hive;
class Acceptor;
//class Connection;
//-----------------------------------------------------------------------------
class Connection : public boost::enable_shared_from_this< Connection >
{
friend class Acceptor;
friend class Hive;
private:
boost::shared_ptr< Hive > m_hive;
boost::asio::ip::tcp::socket m_socket;
boost::asio::strand m_io_strand;
boost::posix_time::ptime m_last_time;
std::vector< uint8_t > m_recv_buffer;
std::list< int32_t > m_pending_recvs;
std::list< std::vector< uint8_t > > m_pending_sends;
int32_t m_receive_buffer_size;
boost::asio::deadline_timer m_retryTimer ;
int32_t m_retryTimerInterval;
boost::asio::deadline_timer m_connectTimer;
int32_t m_connectTimerInterval;
boost::asio::deadline_timer m_sendTimer;
int32_t m_sendTimerInterval;
void DispatchSendTimer( const boost::system::error_code & error );
void HandleSendTimer( const boost::system::error_code & error );
volatile uint32_t m_error_state;
我收到的错误消息与此代码中的以下行有关:
boost::asio::strand m_io_strand;
我收到的错误消息如下:
../include/TCPNetwork.h:53:9: error: invalid use of template-name ‘boost::asio::strand’ without an argument list
那我应该如何引用 m_io_strand 呢?
【问题讨论】:
-
我不确定你指的是什么。我应该补充一点,我更像是一个 LAMP 人,C++ 经常落入我的怀抱。所以,我正在尝试使用和理解它,但我需要一些帮助,因此提出了这个问题。
-
我的意思是我们需要一些东西来复制粘贴和编译,不需要修改,也不需要与问题无关的东西。这有利于您、我们和未来的读者,因为它更易于阅读和理解。
-
例如,this 编译得非常好,显然不是您面临的问题。
-
谢谢你!我没有遇到 wandbox.org 并且非常有帮助。