使用boost::asio::async\u read读取缓冲区时出现问题
你好 我的项目中有一个Types.hpp文件。其中我有:使用boost::asio::async\u read读取缓冲区时出现问题,boost,asynchronous,buffer,boost-asio,Boost,Asynchronous,Buffer,Boost Asio,你好 我的项目中有一个Types.hpp文件。其中我有: .... namespace RC { ..... ..... struct ViewSettings { .... }; ..... } 在Server.cpp文件中,我包含了这个Types.hpp文件,我有: class Session { ..... RC::ViewSettings tmp; boost::asio::async_read(socket_, boost::asio::buff
....
namespace RC
{
.....
.....
struct ViewSettings
{
....
};
.....
}
在Server.cpp文件中,我包含了这个Types.hpp文件,我有:
class Session
{
.....
RC::ViewSettings tmp;
boost::asio::async_read(socket_, boost::asio::buffer(&tmp, sizeof(RC::ViewSettings)),
boost::bind(&Session::Finish_Reading_Data, shared_from_this(), boost::asio::placeholders::error));
.....
}
在编译过程中,我发现了一个错误:
error C2825: 'F': must be a class or namespace when followed by '::'
: see reference to class template instantiation 'boost::_bi::result_traits<R,F>'
being compiled with
[
R=boost::_bi::unspecified,
F=void (__thiscall Session::* )(void)
]
: see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>'
being compiled with
[
R=boost::_bi::unspecified,
F=void (__thiscall Session::* )(void),
L=boost::_bi::list2<boost::_bi::value<boost::shared_ptr<Session>>,boost::arg<1>>
]
error C2039: 'result_type' : is not a member of '`global namespace''
请帮忙。这里有什么问题?
提前感谢。您正在尝试传输一个结构,而不仅仅是一个简单的类型。这就是为什么它可以与int一起工作,而不能与struct一起工作 我认为这是在序列化领域,因此我认为您需要boost.serialization
检查这个序列化示例,也许这会对您有所帮助。您需要从boost::enable_shared_中继承会话
int w;
boost::asio::async_read(socket_, boost::asio::buffer(&w, sizeof(int)),
boost::bind(&Session::Handle_Read_Width, shared_from_this(), boost::asio::placeholders::error));