有什么用ASIO ::占位符::错误 [英] What's the use of asio::placeholder::error
问题描述
在ASIO库经过了很多的例子,也就是一个错误的参数;
<一href=\"http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp\">http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp
The asio library passes an error parameter in a lot of its examples, ie; http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp
这是什么参数的意义呢? ASIO是否实际上错误填充此参数?
What's the point of this parameter? Does asio actually populate this parameter with errors?
如果我从我的处理函数删除它,它编译罚款。
If I remove it from my handler function it compiles fine.
推荐答案
其实, ASIO ::占位符::误差
等同于 _1
Boost.Bind占位符,所以绑定(安培; my_class ::处理程序,为此,ASIO ::占位符::错误)
就像绑定。(安培; my_class ::处理程序,为此,_1)
Actually, asio::placeholders::error
is equivalent to _1
Boost.Bind placeholder, so bind(&my_class::handler, this, asio::placeholders::error)
is just like bind(&my_class::handler, this, _1)
.
当这个处理程序是由Boost.Asio的完成处理程序分发器调用,错误_ code
作为第一个参数传递给这个函数传递。
When this handler is being called by Boost.Asio completion-handler dispatcher, error_code
is passed as the 1st argument to this function.
不过,您可以随时绑定
的预计少的参数(在这种情况下 - 零) - 一种功能,当粘合剂被调用,的any额外的参数会被忽略。
However, you can always bind
a function that expects less arguments (in this case - zero) - when the binder gets invoked, any extra arguments are silently ignored.
这篇关于有什么用ASIO ::占位符::错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!