【发布时间】:2015-04-04 03:06:33
【问题描述】:
下面的代码成功地向给定端点发送了一条异步消息。
// message is a boost::shared_ptr<std::string>
// open a UDP socket
boost::asio::ip::udp::socket socket(ioService);
socket.open(boost::asio::ip::udp::v4());
// create the remote endpoint
boost::asio::ip::udp::endpoint remoteEndpoint(boost::asio::ip::address_v4::from_string(address), port);
// asynchronously send a datagram to the remote endpoint
socket.async_send_to(boost::asio::buffer(*message),
remoteEndpoint,
boost::bind(&MyClass::handler,
this,
message,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
socket.close();
但是,如果我将 message 的类型更改为 std::shared_ptr<std::string> 而不是 boost::shared_ptr<std::string>,那么对 async_send_to 的调用将无法编译。
错误是:
boost/boost/bind/bind.hpp:457:9: No matching function for call to object of type 'boost::_mfi::mf3<void, MyClass, const boost::shared_ptr<std::__1::basic_string<char> > &, const boost::system::error_code &, unsigned long>'.
有人可以解释什么是错的吗?可能是因为我正在使用 boost::bind 吗?
【问题讨论】:
-
MyClass::handler的原型是什么?
标签: c++ c++11 boost-asio shared-ptr boost-bind