我正在浏览http://gwenael-dunand.developpez.com/tutoriels/cpp/boost/asio/上的这个加速教程,它给了我很多错误
boost::bind(&tcp_server::handle_accept, this, new_connection, boost::asio::placeholders::error);
我在这里使用
m_acceptor.async_accept(new_connection.socket(), boost::bind(&tcp_server::handle_accept, this, new_connection, boost::asio::placeholders::error));
我为这行的prsence收到了这个巨大的错误
In file included from /usr/include/boost/asio/basic_socket.hpp:24,
from /usr/include/boost/asio/basic_datagram_socket.hpp:25,
from /usr/include/boost/asio.hpp:20,
from /home/dipro/Development/asio/main.cpp:5:
/usr/include/boost/noncopyable.hpp: In copy constructor ‘boost::asio::basic_io_object<boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_io_object(const boost::asio::basic_io_object<boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’:
/usr/include/boost/noncopyable.hpp:27: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
/usr/include/boost/asio/basic_io_object.hpp:30: error: within this context
In file included from /usr/include/boost/asio/datagram_socket_service.hpp:33,
from /usr/include/boost/asio/basic_datagram_socket.hpp:26,
from /usr/include/boost/asio.hpp:20,
from /home/dipro/Development/asio/main.cpp:5:
/usr/include/boost/noncopyable.hpp: In copy constructor ‘boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp, boost::asio::detail::epoll_reactor<false> >::implementation_type::implementation_type(const boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp, boost::asio::detail::epoll_reactor<false> >::implementation_type&)’:
/usr/include/boost/noncopyable.hpp:27: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
/usr/include/boost/asio/detail/reactive_socket_service.hpp:58: error: within this context
In file included from /usr/include/boost/asio/basic_socket.hpp:24,
from /usr/include/boost/asio/basic_datagram_socket.hpp:25,
from /usr/include/boost/asio.hpp:20,
from /home/dipro/Development/asio/main.cpp:5:
/usr/include/boost/asio/basic_io_object.hpp: In copy constructor ‘boost::asio::basic_io_object<boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_io_object(const boost::asio::basic_io_object<boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’:
/usr/include/boost/asio/basic_io_object.hpp:30: note: synthesized method ‘boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp, boost::asio::detail::epoll_reactor<false> >::implementation_type::implementation_type(const boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp, boost::asio::detail::epoll_reactor<false> >::implementation_type&)’ first required here
In file included from /usr/include/boost/asio/basic_datagram_socket.hpp:25,
from /usr/include/boost/asio.hpp:20,
from /home/dipro/Development/asio/main.cpp:5:
/usr/include/boost/asio/basic_socket.hpp: In copy constructor ‘boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_socket(const boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’:
/usr/include/boost/asio/basic_socket.hpp:45: note: synthesized method ‘boost::asio::basic_io_object<boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_io_object(const boost::asio::basic_io_object<boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’ first required here
In file included from /usr/include/boost/asio.hpp:28,
from /home/dipro/Development/asio/main.cpp:5:
/usr/include/boost/asio/basic_stream_socket.hpp: In copy constructor ‘boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_stream_socket(const boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’:
/usr/include/boost/asio/basic_stream_socket.hpp:49: note: synthesized method ‘boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_socket(const boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’ first required here
/home/dipro/Development/asio/main.cpp: In copy constructor ‘tcp_connection::tcp_connection(const tcp_connection&)’:
/home/dipro/Development/asio/main.cpp:9: note: synthesized method ‘boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::basic_stream_socket(const boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >&)’ first required here
/home/dipro/Development/asio/main.cpp: In member function ‘void tcp_server::start_accept()’:
/home/dipro/Development/asio/main.cpp:39: note: synthesized method ‘tcp_connection::tcp_connection(const tcp_connection&)’ first required here
/home/dipro/Development/asio/main.cpp:39: error: initializing argument 3 of ‘boost::_bi::bind_t<R, boost::_mfi::mf2<R, T, A1, A2>, typename boost::_bi::list_av_3<A1, A2, A3>::type> boost::bind(R (T::*)(B1, B2), A1, A2, A3) [with R = void, T = tcp_server, B1 = tcp_connection&, B2 = const boost::system::error_code&, A1 = tcp_server*, A2 = tcp_connection, A3 = boost::arg<1> (*)()]’
make[2]: *** [CMakeFiles/asio.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/asio.dir/all] Error 2
make: *** [all] Error 2
dipro@bong:~/Development/asio/build$
答案 0 :(得分:2)
该教程似乎有错误。参数new_connection
是通过引用获取的,因此绑定需要使用boost::ref
,否则它将尝试复制它,因为错误显示类型是 noncopyable 。将 bind 更改为:
boost::bind(
&tcp_server::handle_accept
, this
, boost::ref(new_connection) // << pass by reference
, boost::asio::placeholders::error);