async_read_some模板错误
Asio async_read_some template error
我正在使用非boost asio编写一个简单的异步服务器。我遇到了一个巨大的模板错误,坦率地说,我甚至无法想象这一切意味着什么。
作为参考,我的代码看起来很像http://think-async.com/Asio/asio-1.5.3/src/examples/http/server3/connection.cpp .
下面是我的代码:void client_connection::serve()
{
// std::cout << "Began serving connection" << std::endl;
// refer to http server 3 connection.cpp
this->socket_.async_read_some(asio::buffer(&protocol_version_, 1), this->strand_.wrap(std::bind(&client_connection::handle_read, this->shared_from_this(), asio::placeholders::error, asio::placeholders::bytes_transferred)));
// 65535 max tcp size
}
void client_connection::handle_read(const asio::error_code& error_, std::size_t bytes_)
{
if (error_) return;
// for debug: print out all the recieved bytes
std::cout << std::hex << protocol_version_ << " " << std::endl;
this->serve();
}
错误如下:
1>C:Program Files (x86)Microsoft Visual Studio 11.0VCincludefunctional(1152): error : no instance of overloaded function "std::_Pmf_wrap<_Pmf_t, _Rx, _Farg0, _V0_t, _V1_t, std::_Nil, std::_Nil, std::_Nil, std::_Nil, std::_Nil>::operator() [with _Pmf_t=void (client_connection::*)(const asio::error_code &, size_t={unsigned int}), _Rx=void, _Farg0=client_connection, _V0_t=const asio::error_code &, _V1_t=size_t={unsigned int}]" matches the argument list
1> argument types are: (client_connection *, boost::arg<1>, boost::arg<2>)
1> object type is: std::_Pmf_wrap<void (client_connection::*)(const asio::error_code &, size_t), void, client_connection, const asio::error_code &, size_t, std::_Nil, std::_Nil, std::_Nil, std::_Nil, std::_Nil>
1> _VARIADIC_EXPAND_0X(_CLASS_BIND, , , , )
1> ^
(+~20 not very relevant lines)
我有预感它与shared_from_this有关,但无论我是否删除shared_from_this行为,错误都会发生。
任何形式的帮助都是非常感谢的。
我相信asio::placeholders::*
与boost::bind
一起工作,但我不确定他们是否与std::bind
一起工作。尝试std::placeholders::_1
和std::placeholders::_2
代替,或使用boost::bind
。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- 错误:在类型 "blah blah" 的绑定引用中删除限定符以初始化"some other blah blah"
- 为什么GCC可以编译std::exception("some error msg")而没有错误?
- C++ 字符值 + "-some words here-"但错误 C2110
- Eclipse CDT 无法在 Windows 中运行编译的可执行文件,并显示错误"terminated, exit value: <some number>"