调用boost v1.58中的函数时出现模板名称使用无效错误

Invalid use of template name error when calling function in boost v1.58

本文关键字:错误 无效 v1 boost 函数 调用      更新时间:2023-10-16

我有一个利用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?

应该编写boost::asio::io_service::strand而不是boost::asio::strand。此外,您应该在类的构造函数中使用io_service对象初始化strand