我有这段代码需要通过struct
传递boost:bind
变量
client(boost::asio::io_service& io_service,
boost::asio::ssl::context& context,
const std::string& server, const std::string& path, const std::string& port, RESTClient::response& resp)
: resolver_(io_service),
socket_(io_service, context)
{
resp.body = "first!"; // Works fine
std::ostream request_stream(&request_);
request_stream << "GET " << path << " HTTP/1.0\r\n";
request_stream << "Host: " << server << "\r\n";
request_stream << "Accept: */*\r\n";
request_stream << "Connection: close\r\n\r\n";
tcp::resolver::query query(server, port);
resolver_.async_resolve(query,
boost::bind(&client::handle_resolve, this,
boost::asio::placeholders::error,
boost::asio::placeholders::iterator,
resp));
}
但是在这里我添加了一个不起作用的更改:
void handle_resolve(const boost::system::error_code& err,
tcp::resolver::iterator endpoint_iterator, RESTClient::response &resp)
{
(&resp)->body = "Haloo!!!"; // not working
}
body
调用后boost::bind
可以设置的方式是什么?
答案 0 :(得分:5)
<div ng-include="'columns/' + column.type + '.html'"></div>
默认复制其所有参数。来自docs:
绑定的参数是复制并由返回的函数对象在内部保存。例如,在以下代码中:
bind
int i = 5; bind(f, i, _1);
的值的副本存储在函数对象中。i
和boost::ref
可用于使函数对象存储对象的引用,而不是副本
在这种情况下会是:
boost::cref