c++ - Pass argument with boost::bind not working -


i have code need pass on struct variable through 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));         } 

however here added change not work:

void handle_resolve(const boost::system::error_code& err,     tcp::resolver::iterator endpoint_iterator, restclient::response &resp) {     (&resp)->body = "haloo!!!"; // not working } 

in way body can set after boost::bind call?

bind copies of arguments default. docs:

the arguments bind takes copied , held internally returned function object. example, in following code:

int = 5; bind(f, i, _1); 

a copy of value of i stored function object. boost::ref , boost::cref can used make function object store reference object, rather copy

which in case be:

boost::bind(&client::handle_resolve, this,             boost::asio::placeholders::error,             boost::asio::placeholders::iterator,             boost::ref(resp)));             ^^^^^^^^^^^^^^^^^ 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -