使用boost asio时bind报错大家好:写了个asio的小程序,没想到就一点代码也出错了。。。报这个错:error C2248:
使用boost asio时bind报错
大家好:
写了个asio的小程序,没想到就一点代码也出错了。。。
报这个错:
error C2248: “boost::noncopyable_::noncopyable::noncopyable”: 无法访问 private 成员(在“boost::noncopyable_::noncopyable”类中声明)
程序是这样的:
- C/C++ code
#include <iostream>#include <boost/asio.hpp>#include <boost/bind.hpp>#include <boost/shared_ptr.hpp>#include <string>using namespace boost::asio;using namespace boost;using namespace boost::system;io_service ios;ip::tcp::acceptor* apt;//发现这里参数apt改为传指针就不会报错了void accept_hander(ip::tcp::acceptor _apt, shared_ptr<ip::tcp::socket> pSocket){}int _tmain(int argc, _TCHAR* argv[]){ apt = new ip::tcp::acceptor(ios, ip::tcp::endpoint(ip::tcp::v4(), 5000)); shared_ptr<ip::tcp::socket> pSocket(new ip::tcp::socket(ios)); apt->async_accept(*pSocket, bind(&accept_hander, *apt, pSocket)); ios.run(); return 0;}请问出现这个错误的原因是什么呢?
[解决办法]
瞎猜一下吧:
对象不允许值拷贝,所以用指针 或者boost::ref来传递这样的对象的值
