编译器错误提升:: asio :: placeholder ::错误与boost v1.69

问题描述 投票:0回答:1

当使用32位g ++ v5.1和boost v1.63构建代码块v17时,以下代码编译并运行预期结果(3秒后在控制台上完成)

#include <iostream>
#include <thread>
#include <boost/bind.hpp>
#include <boost/asio.hpp>

namespace pinmed
{

class cTimedEvent
{
public:

    cTimedEvent( boost::asio::io_service& ios )
        : myTimer( ios )
    {

    }

    /** Schedule one-off timed event
    @param[in] msecs delay from now
    @param[in] handler to call when delay expires
    */
    template<
        typename H >
    void Schedule(
        int msecs,
        H handler )
    {
        myTimer.expires_from_now(
            boost::posix_time::milliseconds( msecs ));
        myTimer.async_wait( handler );
    }

private:
    boost::asio::deadline_timer myTimer;
};

class cClass
{
public:
    cClass(  boost::asio::io_service& ios )
        : myTimedEvent( ios )
    {
        myTimedEvent.Schedule(
            3000,
            boost::bind(
                &cClass::handler,
                this,
                boost::asio::placeholders::error) );
    }
    void handler(
        const boost::system::system_error& e)
    {
        std::cout << "done\n";
    }

private:
    cTimedEvent myTimedEvent;
};

}


using namespace std;

int main()
{
    boost::asio::io_service ios;
    pinmed::cClass theClass( ios );
    ios.run();
    return 0;
}

但是,当我使用boost v1.69“升级”到64位g ++ v8.2时,我得到一个可怕的编译器错误:

-------------- Build: Debug in test_timed (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -fexceptions -g -std=c++11 -IC:\Users\James\code\boost\boost_1_69_0 -c C:\Users\James\code\test_timed\main.cpp -o obj\Debug\main.o
g++.exe -LC:\Users\James\code\boost\v1_63_gcc51\stage\lib -LC:\Users\James\code\nana-1.6.2\build\codeblocks -o \bin\test_timed.exe obj\Debug\main.o   -lboost_thread-mgw51-mt-1_63 -lboost_system-mgw51-mt-1_63 -lboost_program_options-mgw51-mt-1_63 -lboost_filesystem-mgw51-mt-1_63 -lws2_32
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
                 from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp: In instantiation of 'void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>; A = boost::_bi::rrlist1<const boost::system::error_code&>; A1 = boost::_bi::value<pinmed::cClass*>; A2 = boost::arg<1> (*)()]':
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:1306:50:   required from 'boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&&) [with A1 = const boost::system::error_code&; R = void; F = boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>; L = boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()>; boost::_bi::bind_t<R, F, L>::result_type = void]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/bind_handler.hpp:65:5:   required from 'void boost::asio::detail::binder1<Handler, Arg1>::operator()() [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >; Arg1 = boost::system::error_code]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/handler_invoke_hook.hpp:69:11:   required from 'void boost::asio::asio_handler_invoke(Function&, ...) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >, boost::system::error_code>]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/handler_invoke_helpers.hpp:37:22:   required from 'void boost_asio_handler_invoke_helpers::invoke(Function&, Context&) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >, boost::system::error_code>; Context = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/handler_work.hpp:82:46:   required from 'void boost::asio::detail::handler_work<Handler, boost::asio::system_executor>::complete(Function&, Handler&) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >, boost::system::error_code>; Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/wait_handler.hpp:72:7:   required from 'static void boost::asio::detail::wait_handler<Handler>::do_complete(void*, boost::asio::detail::operation*, const boost::system::error_code&, std::size_t) [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >; boost::asio::detail::operation = boost::asio::detail::win_iocp_operation; std::size_t = long long unsigned int]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/wait_handler.hpp:39:15:   required from 'boost::asio::detail::wait_handler<Handler>::wait_handler(Handler&) [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/deadline_timer_service.hpp:236:11:   required from 'void boost::asio::detail::deadline_timer_service<Time_Traits>::async_wait(boost::asio::detail::deadline_timer_service<Time_Traits>::implementation_type&, Handler&) [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >; Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/basic_deadline_timer.hpp:610:5:   required from 'typename boost::asio::async_result<typename std::decay<_U1>::type, void(boost::system::error_code)>::return_type boost::asio::basic_deadline_timer<Time, TimeTraits>::async_wait(WaitHandler&&) [with WaitHandler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >&; Time = boost::posix_time::ptime; TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>; typename boost::asio::async_result<typename std::decay<_U1>::type, void(boost::system::error_code)>::return_type = void]'
C:\Users\James\code\test_timed\main.cpp:31:9:   required from 'void pinmed::cTimedEvent::Schedule(int, H) [with H = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\test_timed\main.cpp:49:51:   required from here
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:319:35: error: no match for call to '(boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>) (pinmed::cClass*&, const boost::system::error_code&)'
         unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn.hpp:215,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/mem_fn.hpp:22,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:26,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
                 from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:163:7: note: candidate: 'R boost::_mfi::mf1<R, T, A1>::operator()(T*, A1) const [with R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
     R operator()(T * p, A1 a1) const
       ^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:163:7: note:   no known conversion for argument 2 from 'const boost::system::error_code' to 'const boost::system::system_error&'
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:168:25: note: candidate: 'template<class U> R boost::_mfi::mf1<R, T, A1>::operator()(U&, A1) const [with U = U; R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
     template<class U> R operator()(U & u, A1 a1) const
                         ^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:168:25: note:   template argument deduction/substitution failed:
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
                 from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:319:35: note:   cannot convert '(& a)->boost::_bi::rrlist1<const boost::system::error_code&>::operator[](boost::_bi::storage2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()>::a2_)' (type 'const boost::system::error_code') to type 'const boost::system::system_error&'
         unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn.hpp:215,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/mem_fn.hpp:22,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:26,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
                 from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:176:25: note: candidate: 'template<class U> R boost::_mfi::mf1<R, T, A1>::operator()(const U&, A1) const [with U = U; R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
     template<class U> R operator()(U const & u, A1 a1) const
                         ^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:176:25: note:   template argument deduction/substitution failed:
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
                 from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:319:35: note:   cannot convert '(& a)->boost::_bi::rrlist1<const boost::system::error_code&>::operator[](boost::_bi::storage2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()>::a2_)' (type 'const boost::system::error_code') to type 'const boost::system::system_error&'
         unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn.hpp:215,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/mem_fn.hpp:22,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:26,
                 from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
                 from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:184:7: note: candidate: 'R boost::_mfi::mf1<R, T, A1>::operator()(T&, A1) const [with R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
     R operator()(T & t, A1 a1) const
       ^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:184:7: note:   no known conversion for argument 1 from 'pinmed::cClass*' to 'pinmed::cClass&'
Process terminated with status 1 (0 minute(s), 8 second(s))
1 error(s), 12 warning(s) (0 minute(s), 8 second(s))
c++ boost-asio
1个回答
2
投票

deadline_timer::async_wait方法的处理程序的签名是什么?根据reference,它是:

void handler(
  const boost::system::error_code& error // Result of operation.
);

你的签名是什么?

void handler(
    const boost::system::system_error& e)
{
    std::cout << "done\n";
}

将处理程序更改为:

void handler(
    const boost::system::error_code& e)
{
    std::cout << "done\n";
}
© www.soinside.com 2019 - 2024. All rights reserved.