2009-08-14 3 views
0

私はブーストライブラリを使ってタイマーを設定しようとしています。ブーストタイマバインディング

class ContactList { 
public: 
    ContactList(); 
    virtual ~ContactList(); 
    int Start(); 
    int readFromFile(); 
    int dumpList(); 
    void checkContacts(const boost::system::error_code& error); 
    void initializeTimer(); 

private: 
    std::list<Contact*> CList; 
    boost::asio::deadline_timer dt; 
    boost::asio::io_service ios; 
}; 

int ContactList::Start(){ 
... 
this->initializeTimer(); 
} 

void ContactList::checkContacts(const boost::system::error_code& error){ 
    std::cout<<"__Here we go!"<<std::endl; 
    ios.reset(); 
    initializeTimer(); 
} 

void ContactList::initializeTimer(){ 
    dt.expires_from_now(boost::posix_time::seconds(4)); 
    dt.async_wait(boost::bind(&ContactList::checkContacts, this, boost::asio::placeholders::error)); 
    ios.run(); 
} 

とコンパイラが言って、多くのことを不平を言う:

基本的に、これは私が書いたものである

g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"kad/ContactList.d" -MT"kad/ContactList.d" -o"kad/ContactList.o" "../kad/ContactList.cpp" 
../kad/ContactList.cpp: In constructor ‘kad::ContactList::ContactList()’: 
../kad/ContactList.cpp:12: error: no matching function for call to ‘boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >::basic_deadline_timer()’ 
/usr/include/boost/asio/basic_deadline_timer.hpp:177: note: candidates are: boost::asio::basic_deadline_timer<Time, TimeTraits, TimerService>::basic_deadline_timer(boost::asio::io_service&, const typename TimeTraits::duration_type&) [with Time = boost::posix_time::ptime, TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>, TimerService = boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> >] 
/usr/include/boost/asio/basic_deadline_timer.hpp:158: note:     boost::asio::basic_deadline_timer<Time, TimeTraits, TimerService>::basic_deadline_timer(boost::asio::io_service&, const typename TimeTraits::time_type&) [with Time = boost::posix_time::ptime, TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>, TimerService = boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> >] 
/usr/include/boost/asio/basic_deadline_timer.hpp:142: note:     boost::asio::basic_deadline_timer<Time, TimeTraits, TimerService>::basic_deadline_timer(boost::asio::io_service&) [with Time = boost::posix_time::ptime, TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>, TimerService = boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> >] 
/usr/include/boost/asio/basic_deadline_timer.hpp:122: note:     boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >::basic_deadline_timer(const boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >&) 
/usr/include/boost/mem_fn.hpp: In member function ‘R& boost::_mfi::dm<R, T>::operator()(T*) const [with R = void()(const boost::system::error_code&), T = kad::ContactList]’: 
/usr/include/boost/bind.hpp:222: instantiated from ‘R boost::_bi::list1<A1>::operator()(boost::_bi::type<R>, F&, A&, long int) [with R = void (&)(const boost::system::error_code&), F = boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, A = boost::_bi::list1<boost::system::error_code&>, A1 = boost::_bi::value<kad::ContactList*>]’ 
/usr/include/boost/bind/bind_template.hpp:32: instantiated from ‘typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = boost::system::error_code, R = void (&)(const boost::system::error_code&), F = boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, L = boost::_bi::list1<boost::_bi::value<kad::ContactList*> >]’ 
/usr/include/boost/asio/detail/bind_handler.hpp:39: instantiated from ‘void boost::asio::detail::binder1<Handler, Arg1>::operator()() [with Handler = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, Arg1 = boost::system::error_code]’ 
/usr/include/boost/asio/handler_invoke_hook.hpp:63: instantiated from ‘void boost::asio::asio_handler_invoke(Function, ...) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>]’ 
/usr/include/boost/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void boost_asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>, Context = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >]’ 
/usr/include/boost/asio/detail/bind_handler.hpp:72: instantiated from ‘void boost::asio::detail::asio_handler_invoke(const Function&, boost::asio::detail::binder1<Handler, Arg1>*) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>, Handler = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, Arg1 = boost::system::error_code]’ 
/usr/include/boost/asio/detail/handler_invoke_helpers.hpp:39: instantiated from ‘void boost_asio_handler_invoke_helpers::invoke(const Function&, Context*) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>, Context = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>]’ 
/usr/include/boost/asio/detail/handler_queue.hpp:192: instantiated from ‘static void boost::asio::detail::handler_queue::handler_wrapper<Handler>::do_call(boost::asio::detail::handler_queue::handler*) [with Handler = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>]’ 
/usr/include/boost/asio/detail/handler_queue.hpp:172: instantiated from ‘boost::asio::detail::handler_queue::handler_wrapper<Handler>::handler_wrapper(Handler) [with Handler = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>]’ 
/usr/include/boost/asio/detail/handler_alloc_helpers.hpp:138: instantiated from ‘boost::asio::detail::handler_ptr<Alloc_Traits>::handler_ptr(boost::asio::detail::raw_handler_ptr<Alloc_Traits>&, Arg1&) [with Arg1 = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>, Alloc_Traits = boost::asio::detail::handler_alloc_traits<boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>, boost::asio::detail::handler_queue::handler_wrapper<boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code> > >]’ 
/usr/include/boost/asio/detail/handler_queue.hpp:117: instantiated from ‘static boost::asio::detail::handler_queue::handler* boost::asio::detail::handler_queue::wrap(Handler) [with Handler = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>]’ 
/usr/include/boost/asio/detail/task_io_service.hpp:190: instantiated from ‘void boost::asio::detail::task_io_service<Task>::post(Handler) [with Handler = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>, Task = boost::asio::detail::epoll_reactor<false>]’ 
/usr/include/boost/asio/impl/io_service.ipp:126: instantiated from ‘void boost::asio::io_service::post(Handler) [with CompletionHandler = boost::asio::detail::binder1<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, boost::system::error_code>]’ 
/usr/include/boost/asio/detail/deadline_timer_service.hpp:172: instantiated from ‘void boost::asio::detail::deadline_timer_service<Time_Traits, Timer_Scheduler>::wait_handler<Handler>::operator()(const boost::system::error_code&) [with Handler = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>, Timer_Scheduler = boost::asio::detail::epoll_reactor<false>]’ 
/usr/include/boost/asio/detail/timer_queue.hpp:299: instantiated from ‘static void boost::asio::detail::timer_queue<Time_Traits>::timer<Handler>::complete_handler(boost::asio::detail::timer_queue<Time_Traits>::timer_base*, const boost::system::error_code&) [with Handler = boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::detail::epoll_reactor<false> >::wait_handler<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > > >, Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>]’ 
/usr/include/boost/asio/detail/timer_queue.hpp:276: instantiated from ‘boost::asio::detail::timer_queue<Time_Traits>::timer<Handler>::timer(const typename Time_Traits::time_type&, Handler, void*) [with Handler = boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::detail::epoll_reactor<false> >::wait_handler<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > > >, Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>]’ 
/usr/include/boost/asio/detail/timer_queue.hpp:71: instantiated from ‘bool boost::asio::detail::timer_queue<Time_Traits>::enqueue_timer(const typename Time_Traits::time_type&, Handler, void*) [with Handler = boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::detail::epoll_reactor<false> >::wait_handler<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > > >, Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>]’ 
/usr/include/boost/asio/detail/epoll_reactor.hpp:414: instantiated from ‘void boost::asio::detail::epoll_reactor<Own_Thread>::schedule_timer(boost::asio::detail::timer_queue<Time_Traits>&, const typename Time_Traits::time_type&, Handler, void*) [with Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>, Handler = boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::detail::epoll_reactor<false> >::wait_handler<boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > > >, bool Own_Thread = false]’ 
/usr/include/boost/asio/detail/deadline_timer_service.hpp:185: instantiated from ‘void boost::asio::detail::deadline_timer_service<Time_Traits, Timer_Scheduler>::async_wait(boost::asio::detail::deadline_timer_service<Time_Traits, Timer_Scheduler>::implementation_type&, Handler) [with Handler = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>, Timer_Scheduler = boost::asio::detail::epoll_reactor<false>]’ 
/usr/include/boost/asio/deadline_timer_service.hpp:157: instantiated from ‘void boost::asio::deadline_timer_service<TimeType, TimeTraits>::async_wait(typename boost::asio::detail::deadline_timer_service<TimeTraits, boost::asio::detail::epoll_reactor<false> >::implementation_type&, WaitHandler) [with WaitHandler = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, TimeType = boost::posix_time::ptime, TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>]’ 
/usr/include/boost/asio/basic_deadline_timer.hpp:374: instantiated from ‘void boost::asio::basic_deadline_timer<Time, TimeTraits, TimerService>::async_wait(WaitHandler) [with WaitHandler = boost::_bi::bind_t<void (&)(const boost::system::error_code&), boost::_mfi::dm<void()(const boost::system::error_code&), kad::ContactList>, boost::_bi::list1<boost::_bi::value<kad::ContactList*> > >, Time = boost::posix_time::ptime, TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>, TimerService = boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> >]’ 
../kad/ContactList.cpp:96: instantiated from here 
/usr/include/boost/mem_fn.hpp:342: error: invalid use of non-static member function 
make: *** [kad/ContactList.o] Error 1 

私は本当に任意のヘルプや提案をいただければと思います。 ありがとうございました

答えて

4

私は、コンパイラがコンストラクタに問題があることを伝えようとしていると思います。あなたはそれのためのコードを含んでいませんでしたが、deadline_timerメンバーdtを初期化していないと思います。あなたがdefined constructorsのいずれかを選択しなければならない -

ContactList::ContactList() 
{ 
} 

問題があり、deadline_timerクラスが定義されたデフォルトコンストラクタを持っていないこと:たぶん、あなたはこのような何かを行います。選択する3つがあるように表示されます。

basic_deadline_timer(
    boost::asio::io_service & io_service); 

basic_deadline_timer(
    boost::asio::io_service & io_service, 
    const time_type & expiry_time); 

basic_deadline_timer(
    boost::asio::io_service & io_service, 
    const duration_type & expiry_time); 

は明らかにテンプレートエラーが読みにくいと役に立たない多くの情報を含んで - それらを解析するには、芸術的な表現形式の何かとなっています。 stlfiltのインストールを調べることができます。これは、エラーメッセージをいくらか簡略化できるPerlスクリプトのセットです。

+0

はい。聖なる言葉。私は "dt = new boost :: asio :: deadline_timer(ios);"を追加しました。コンストラクタにdtをポインタとして渡します。どうもありがとう! (まだこのサイトが大好きです) –