2009-07-19 122 views
4

我有這個頭(重做從升壓ASIO爲例):升壓初學者,升壓::綁定噩夢

#ifndef MSGSRV_H_ 
#define MSGSRV_H_ 
#include <asio.hpp> 
#include <boost/array.hpp> 
#include <boost/bind.hpp> 
#include <boost/shared_ptr.hpp> 
#include <boost/system/error_code.hpp> 


namespace msgSrv { 

class msgSrv { 

private: 
    asio::ip::udp::socket *asioSocket; 
    asio::io_service *asioIoService; 
    int listenPort; 
    boost::array<char,1> rcvBuff; 
    asio::ip::udp::endpoint lastRcvdPcktEndp; 

public: 
    msgSrv(int listenPort); 
    virtual ~msgSrv(); 

    void start(); 
    void pckRcvd(boost::system::error_code &, std::size_t); 
}; 

} 

,並在.cpp:

#include "msgSrv.h" 

namespace msgSrv { 

    msgSrv::msgSrv(int listenPort) { 
     // TODO Auto-generated constructor stub 
     this->listenPort = listenPort; 
     try{ 
      asioIoService = new asio::io_service(); 
      asioSocket = new asio::ip::udp::socket(*asioIoService, asio::ip::udp::endpoint(asio::ip::udp::v4(), listenPort)); //new asio::ip::udp::socket_(*asioIoService, udp::endpoint(udp::v4(), listenPort)); 
     }catch(std::exception &e){ 
      std::cerr << "Error initializing ioservice or socket:" << e.what(); 
     } 
    } 

    msgSrv::~msgSrv() { 
     // TODO Auto-generated destructor stub 
     delete asioIoService; 
     delete asioSocket; 
    } 

    void msgSrv::start(){ 



     asioSocket->async_receive_from(
       asio::buffer(rcvBuff), lastRcvdPcktEndp, 
       boost::bind(&msgSrv::pckRcvd, this, 
        asio::placeholders::error, 
        asio::placeholders::bytes_transferred)); 

    } 

    void msgSrv::pckRcvd(boost::system::error_code &error, std::size_t bytesRcvd){ 
     std::cout << "Rcvd!\n"; 
    } 

} 

現在,它拒絕編譯,給出無法理解的結果:

> make all 
Building file: ../src/msgSrv/msgSrv.cpp 
Invoking: GCC C++ Compiler 
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/msgSrv/msgSrv.d" -MT"src/msgSrv/msgSrv.d" -o"src/msgSrv/msgSrv.o" "../src/msgSrv/msgSrv.cpp" 
/usr/include/boost/bind.hpp: In member function ‘void boost::_bi::list3<A1, A2, A3>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, A = boost::_bi::list2<asio::error::basic_errors&, int&>, A1 = boost::_bi::value<msgSrv::msgSrv*>, A2 = boost::arg<1> (*)(), A3 = boost::arg<2> (*)()]’: 
/usr/include/boost/bind/bind_template.hpp:61: instantiated from ‘typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&) [with A1 = asio::error::basic_errors, A2 = int, R = void, F = boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, L = boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()>]’ 
/usr/include/asio/detail/bind_handler.hpp:95: instantiated from ‘void asio::detail::binder2<Handler, Arg1, Arg2>::operator()() [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Arg1 = asio::error::basic_errors, Arg2 = int]’ 
/usr/include/asio/handler_invoke_hook.hpp:62: instantiated from ‘void asio::asio_handler_invoke(Function, ...) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>]’ 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>, Context = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >]’ 
/usr/include/asio/detail/bind_handler.hpp:129: instantiated from ‘void asio::detail::asio_handler_invoke(const Function&, asio::detail::binder2<Handler, Arg1, Arg2>*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>, Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Arg1 = asio::error::basic_errors, Arg2 = int]’ 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>, Context = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>]’ 
/usr/include/asio/detail/handler_queue.hpp:191: instantiated from ‘static void asio::detail::handler_queue::handler_wrapper<Handler>::do_call(asio::detail::handler_queue::handler*) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>]’ 
/usr/include/asio/detail/handler_queue.hpp:171: instantiated from ‘asio::detail::handler_queue::handler_wrapper<Handler>::handler_wrapper(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>]’ 
/usr/include/asio/detail/handler_alloc_helpers.hpp:137: instantiated from ‘asio::detail::handler_ptr<Alloc_Traits>::handler_ptr(asio::detail::raw_handler_ptr<Alloc_Traits>&, Arg1&) [with Arg1 = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>, Alloc_Traits = asio::detail::handler_alloc_traits<asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>, asio::detail::handler_queue::handler_wrapper<asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int> > >]’ 
/usr/include/asio/detail/handler_queue.hpp:116: instantiated from ‘static asio::detail::handler_queue::handler* asio::detail::handler_queue::wrap(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>]’ 
/usr/include/asio/detail/task_io_service.hpp:190: instantiated from ‘void asio::detail::task_io_service<Task>::post(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>, Task = asio::detail::epoll_reactor<false>]’ 
/usr/include/asio/impl/io_service.ipp:125: instantiated from ‘void asio::io_service::post(Handler) [with CompletionHandler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error::basic_errors, int>]’ 
/usr/include/asio/detail/reactive_socket_service.hpp:1376: instantiated from ‘void asio::detail::reactive_socket_service<Protocol, Reactor>::async_receive_from(asio::detail::reactive_socket_service<Protocol, Reactor>::implementation_type&, const MutableBufferSequence&, typename Protocol::endpoint&, int, Handler) [with MutableBufferSequence = asio::mutable_buffers_1, Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Protocol = asio::ip::udp, Reactor = asio::detail::epoll_reactor<false>]’ 
/usr/include/asio/datagram_socket_service.hpp:310: instantiated from ‘void asio::datagram_socket_service<Protocol>::async_receive_from(typename asio::detail::reactive_socket_service<Protocol, asio::detail::epoll_reactor<false> >::implementation_type&, const MutableBufferSequence&, typename Protocol::endpoint&, int, ReadHandler) [with MutableBufferSequence = asio::mutable_buffers_1, ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Protocol = asio::ip::udp]’ 
/usr/include/asio/basic_datagram_socket.hpp:756: instantiated from ‘void asio::basic_datagram_socket<Protocol, DatagramSocketService>::async_receive_from(const MutableBufferSequence&, typename Protocol::endpoint&, ReadHandler) [with MutableBufferSequence = asio::mutable_buffers_1, ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Protocol = asio::ip::udp, DatagramSocketService = asio::datagram_socket_service<asio::ip::udp>]’ 
../src/msgSrv/msgSrv.cpp:37: instantiated from here 
/usr/include/boost/bind.hpp:348: error: no match for call to ‘(boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>) (msgSrv::msgSrv*&, asio::error::basic_errors&, int&)’ 
/usr/include/boost/bind/mem_fn_template.hpp:272: note: candidates are: R boost::_mfi::mf2<R, T, A1, A2>::operator()(T*, A1, A2) const [with R = void, T = msgSrv::msgSrv, A1 = boost::system::error_code&, A2 = unsigned int] 
/usr/include/boost/bind/mem_fn_template.hpp:291: note:     R boost::_mfi::mf2<R, T, A1, A2>::operator()(T&, A1, A2) const [with R = void, T = msgSrv::msgSrv, A1 = boost::system::error_code&, A2 = unsigned int] 
/usr/include/boost/bind.hpp: In member function ‘void boost::_bi::list3<A1, A2, A3>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, A = boost::_bi::list2<asio::error_code&, int&>, A1 = boost::_bi::value<msgSrv::msgSrv*>, A2 = boost::arg<1> (*)(), A3 = boost::arg<2> (*)()]’: 
/usr/include/boost/bind/bind_template.hpp:61: instantiated from ‘typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&) [with A1 = asio::error_code, A2 = int, R = void, F = boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, L = boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()>]’ 
/usr/include/asio/detail/bind_handler.hpp:95: instantiated from ‘void asio::detail::binder2<Handler, Arg1, Arg2>::operator()() [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Arg1 = asio::error_code, Arg2 = int]’ 
/usr/include/asio/handler_invoke_hook.hpp:62: instantiated from ‘void asio::asio_handler_invoke(Function, ...) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>]’ 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>, Context = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >]’ 
/usr/include/asio/detail/bind_handler.hpp:129: instantiated from ‘void asio::detail::asio_handler_invoke(const Function&, asio::detail::binder2<Handler, Arg1, Arg2>*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>, Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Arg1 = asio::error_code, Arg2 = int]’ 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>, Context = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>]’ 
/usr/include/asio/detail/handler_queue.hpp:191: instantiated from ‘static void asio::detail::handler_queue::handler_wrapper<Handler>::do_call(asio::detail::handler_queue::handler*) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>]’ 
/usr/include/asio/detail/handler_queue.hpp:171: instantiated from ‘asio::detail::handler_queue::handler_wrapper<Handler>::handler_wrapper(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>]’ 
/usr/include/asio/detail/handler_alloc_helpers.hpp:137: instantiated from ‘asio::detail::handler_ptr<Alloc_Traits>::handler_ptr(asio::detail::raw_handler_ptr<Alloc_Traits>&, Arg1&) [with Arg1 = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>, Alloc_Traits = asio::detail::handler_alloc_traits<asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>, asio::detail::handler_queue::handler_wrapper<asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int> > >]’ 
/usr/include/asio/detail/handler_queue.hpp:116: instantiated from ‘static asio::detail::handler_queue::handler* asio::detail::handler_queue::wrap(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>]’ 
/usr/include/asio/detail/task_io_service.hpp:190: instantiated from ‘void asio::detail::task_io_service<Task>::post(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>, Task = asio::detail::epoll_reactor<false>]’ 
/usr/include/asio/impl/io_service.ipp:125: instantiated from ‘void asio::io_service::post(Handler) [with CompletionHandler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, int>]’ 
/usr/include/asio/detail/reactive_socket_service.hpp:1390: instantiated from ‘void asio::detail::reactive_socket_service<Protocol, Reactor>::async_receive_from(asio::detail::reactive_socket_service<Protocol, Reactor>::implementation_type&, const MutableBufferSequence&, typename Protocol::endpoint&, int, Handler) [with MutableBufferSequence = asio::mutable_buffers_1, Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Protocol = asio::ip::udp, Reactor = asio::detail::epoll_reactor<false>]’ 
/usr/include/asio/datagram_socket_service.hpp:310: instantiated from ‘void asio::datagram_socket_service<Protocol>::async_receive_from(typename asio::detail::reactive_socket_service<Protocol, asio::detail::epoll_reactor<false> >::implementation_type&, const MutableBufferSequence&, typename Protocol::endpoint&, int, ReadHandler) [with MutableBufferSequence = asio::mutable_buffers_1, ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Protocol = asio::ip::udp]’ 
/usr/include/asio/basic_datagram_socket.hpp:756: instantiated from ‘void asio::basic_datagram_socket<Protocol, DatagramSocketService>::async_receive_from(const MutableBufferSequence&, typename Protocol::endpoint&, ReadHandler) [with MutableBufferSequence = asio::mutable_buffers_1, ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Protocol = asio::ip::udp, DatagramSocketService = asio::datagram_socket_service<asio::ip::udp>]’ 
../src/msgSrv/msgSrv.cpp:37: instantiated from here 
/usr/include/boost/bind.hpp:348: error: no match for call to ‘(boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>) (msgSrv::msgSrv*&, asio::error_code&, int&)’ 
/usr/include/boost/bind/mem_fn_template.hpp:272: note: candidates are: R boost::_mfi::mf2<R, T, A1, A2>::operator()(T*, A1, A2) const [with R = void, T = msgSrv::msgSrv, A1 = boost::system::error_code&, A2 = unsigned int] 
/usr/include/boost/bind/mem_fn_template.hpp:291: note:     R boost::_mfi::mf2<R, T, A1, A2>::operator()(T&, A1, A2) const [with R = void, T = msgSrv::msgSrv, A1 = boost::system::error_code&, A2 = unsigned int] 
/usr/include/boost/bind.hpp: In member function ‘void boost::_bi::list3<A1, A2, A3>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, A = boost::_bi::list2<asio::error_code&, unsigned int&>, A1 = boost::_bi::value<msgSrv::msgSrv*>, A2 = boost::arg<1> (*)(), A3 = boost::arg<2> (*)()]’: 
/usr/include/boost/bind/bind_template.hpp:61: instantiated from ‘typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&) [with A1 = asio::error_code, A2 = unsigned int, R = void, F = boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, L = boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()>]’ 
/usr/include/asio/detail/bind_handler.hpp:95: instantiated from ‘void asio::detail::binder2<Handler, Arg1, Arg2>::operator()() [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Arg1 = asio::error_code, Arg2 = unsigned int]’ 
/usr/include/asio/handler_invoke_hook.hpp:62: instantiated from ‘void asio::asio_handler_invoke(Function, ...) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>]’ 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>, Context = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >]’ 
/usr/include/asio/detail/bind_handler.hpp:129: instantiated from ‘void asio::detail::asio_handler_invoke(const Function&, asio::detail::binder2<Handler, Arg1, Arg2>*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>, Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, Arg1 = asio::error_code, Arg2 = unsigned int]’ 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>, Context = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>]’ 
/usr/include/asio/detail/handler_queue.hpp:191: instantiated from ‘static void asio::detail::handler_queue::handler_wrapper<Handler>::do_call(asio::detail::handler_queue::handler*) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>]’ 
/usr/include/asio/detail/handler_queue.hpp:171: instantiated from ‘asio::detail::handler_queue::handler_wrapper<Handler>::handler_wrapper(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>]’ 
/usr/include/asio/detail/handler_alloc_helpers.hpp:137: instantiated from ‘asio::detail::handler_ptr<Alloc_Traits>::handler_ptr(asio::detail::raw_handler_ptr<Alloc_Traits>&, Arg1&) [with Arg1 = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>, Alloc_Traits = asio::detail::handler_alloc_traits<asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>, asio::detail::handler_queue::handler_wrapper<asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int> > >]’ 
/usr/include/asio/detail/handler_queue.hpp:116: instantiated from ‘static asio::detail::handler_queue::handler* asio::detail::handler_queue::wrap(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>]’ 
/usr/include/asio/detail/task_io_service.hpp:190: instantiated from ‘void asio::detail::task_io_service<Task>::post(Handler) [with Handler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>, Task = asio::detail::epoll_reactor<false>]’ 
/usr/include/asio/impl/io_service.ipp:125: instantiated from ‘void asio::io_service::post(Handler) [with CompletionHandler = asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, asio::error_code, unsigned int>]’ 
/usr/include/asio/detail/reactive_socket_service.hpp:1353: instantiated from ‘void asio::detail::reactive_socket_service<Protocol, Reactor>::receive_from_operation<MutableBufferSequence, Handler>::complete(const asio::error_code&, size_t) [with MutableBufferSequence = asio::mutable_buffers_1, Handler = boost::_bi::bind_t<void, boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>, boost::_bi::list3<boost::_bi::value<msgSrv::msgSrv*>, boost::arg<1> (*)(), 

...等等。我真的不知道該怎麼辦,因爲我不明白錯誤是什麼!

回答

15

由於實例化了大量的模板,錯誤消息很長,但大部分是給出了可能有用的上下文。我已經採取了第一個錯誤,並削減了過長的線。

首先,編譯器說明錯誤的位置,以及哪些模板實例化序列導致特定模板實例導致錯誤被實例化。

/usr/include/boost/bind.hpp: In member function ‘void boost::_bi::list3<A1, A2, A3>::operator()(boost::_bi::type<void>, F&, A&, int) ... 
/usr/include/boost/bind/bind_template.hpp:61: instantiated from ... 
/usr/include/asio/detail/bind_handler.hpp:95: instantiated from ... 
/usr/include/asio/handler_invoke_hook.hpp:62: instantiated from ... 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ... 
/usr/include/asio/detail/bind_handler.hpp:129: instantiated from ... 
/usr/include/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ... 
/usr/include/asio/detail/handler_queue.hpp:191: instantiated from ... 
/usr/include/asio/detail/handler_queue.hpp:171: instantiated from ... 
/usr/include/asio/detail/handler_alloc_helpers.hpp:137: instantiated from ... 
/usr/include/asio/detail/handler_queue.hpp:116: instantiated from ... 
/usr/include/asio/detail/task_io_service.hpp:190: instantiated from ... 
/usr/include/asio/impl/io_service.ipp:125: instantiated from ... 
/usr/include/asio/detail/reactive_socket_service.hpp:1376: instantiated from ... 
/usr/include/asio/datagram_socket_service.hpp:310: instantiated from ... 
/usr/include/asio/basic_datagram_socket.hpp:756: instantiated from ... 

這裏是你的代碼,導致所有發生線路:

../src/msgSrv/msgSrv.cpp:37: instantiated from here 

這裏是真正的錯誤:

/usr/include/boost/bind.hpp:348: error: no match for call to ‘(boost::_mfi::mf2<void, msgSrv::msgSrv, boost::system::error_code&, unsigned int>) (msgSrv::msgSrv*&, asio::error::basic_errors&, int&)’ 
/usr/include/boost/bind/mem_fn_template.hpp:272: note: candidates are: R boost::_mfi::mf2<R, T, A1, A2>::operator()(T*, A1, A2) const [with R = void, T = msgSrv::msgSrv, A1 = boost::system::error_code&, A2 = unsigned int] 
/usr/include/boost/bind/mem_fn_template.hpp:291: note:     R boost::_mfi::mf2<R, T, A1, A2>::operator()(T&, A1, A2) const [with R = void, T = msgSrv::msgSrv, A1 = boost::system::error_code&, A2 = unsigned int] 

對於參數傳遞的目的, msgSrv::msgSrv*&將轉換爲msgSrv::msgSrv*,但A1參數爲參考,boost::system::error_codeasio::error::basic_errors不是參考兼容

編輯:

如果你讀了read handler類型的要求,你會看到處理程序已與爲const error_code類型的升價值第一參數工作。這意味着您的第一個參數必須是const boost::system::error_code&(即常量參考)或boost::system::error_code(非參考參數)。

+1

非常感謝,我仍然需要回到我的盒子,然後試試這一切是否奏效,但請告訴我,謝謝你的工作,試圖解釋。我喜歡這個網站,它充滿了真正的*程序員和豐富的經驗。非常感謝,我會稍後再試。 – gotch4 2009-07-19 19:01:11

1

我沒有用的boost :: ASIO的第一手經驗,但看着錯誤消息:

/usr/include/boost/bind/bind_template.hpp:61: instantiated from ‘typename boost::_bi::result_traits::type boost::_bi::bind_t::operator()(A1&, A2&) [with A1 = asio::error::basic_errors, A2 = int, R = void, F = boost::_mfi::mf2, L = boost::_bi::list3bi::value, boost::arg<1>()(), boost::arg<2> (*)()>]’

,預計pckRcvd有以下特徵:

void pckRcvd(asio::error::basic_errors&, int&); 

莫非如果它不起作用,你嘗試併發回?

+0

不起作用。無論如何,我從教程中複製的示例具有與我使用的相同的簽名,並且如果我嘗試編譯它,它將起作用!所以可能這是我失蹤的愚蠢! – gotch4 2009-07-19 10:30:44

0

仍然不會去。我發現,它接受這個電話綁定(如果我獨自做到這一點):

boost::bind(&msgSrv::pckRcvd, this, asio::placeholders::error(),asio::placeholders::bytes_transferred()) 

與pckRcvd這樣的:

void msgSrv::pckRcvd(boost::system::error_code err, std::size_t siz) 

在使用我將其插入到asioSocket->async_receive_from

asioSocket->async_receive_from(
         asio::buffer(rcvBuff), lastRcvdPcktEndp, 
         boost::bind(&msgSrv::pckRcvd, this, asio::placeholders::error(),asio::placeholders::bytes_transferred())); 

它會開始抱怨。主要錯誤是:

./src/msgSrv/msgSrv.cpp:43: error: no matching function for call to ‘bind(, msgSrv::msgSrv* const, boost::arg<1>, boost::arg<2>)’ /usr/include/boost/bind.hpp:1437: note: candidates are: boost::_bi::bind_t::type> boost::bind(F, A1, A2, A3) [with F = void (msgSrv::msgSrv::*)(boost::system::error_code,

size_t), A1 = msgSrv::msgSrv*, A2 = boost::arg<1>, A3 = boost::arg<2>] /usr/include/boost/bind/bind_mf_cc.hpp:67: note:
boost::_bi::bind_t, typename boost::_bi::list_av_3::type> boost::bind(R (T::)(B1, B2), A1, A2, A3) [with R = void, T = msgSrv::msgSrv, B1 = boost::system::error_code, B2 = size_t, A1 = msgSrv::msgSrv, A2 = boost::arg<1>, A3 = boost::arg<2>]

似乎得到想要一個不同的簽名,所以我覺得我應該以某種方式修改pckRcvd ...但是...怎麼樣?