Boost logo

Boost :

From: Sergey Lukin (lukin.s.v_at_[hidden])
Date: 2006-02-08 07:57:34


I'm new to boost libraries, sorry if this is an off topic question.

I have the following problem:
I want to call method from the PDC class indirectly from another class
(Component).
Method1 from the Component class should be invoked by asynchronous timer.

When I do call like this:
y.Method1(10, boost::bind (DPC::Print1, &x, 2));
Everything works

When I do call like this:
t.async_wait(boost::bind(boost::bind(DPC::Print1,&x, 2), &t));
Everything works either

But when I try to perform indirect call of Print1 from Method1 which is
called by a timer compiler reports a lot of bugs in the boost::bind code
(see part of the log)
t.async_wait(boost::bind(boost::bind(Component::Method1, &y, 10, boost::bind
(DPC::Print1, &x, 2)), &t));
or
t.async_wait(boost::bind(Component::Method1, &y, 10, boost::bind
(DPC::Print1, &x, 2), &t));

Maybe somebody had the similar problem before or knows how to solve it.
Could you please help me with this.

Kind regards

Sergey

TimerTest.cpp

#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

using namespace boost::posix_time;
using namespace std;

class DPC
{
public:
 void Print1(int a)
 {
  cout << "A = " << a << endl;
 }
};

class Component
{
public:
 template <typename Handler>
 void Method1 (int x ,Handler h)
 {
  x++;
  h();
 }
};

void main()
{
 DPC x;
 Component y;

 //y.Method1(10, boost::bind (DPC::Print1, &x, 2));

 boost::asio::demuxer d;
 // an asyn timer which calls
 boost::asio::deadline_timer t(d, boost::posix_time::seconds(1));

 // t.async_wait(boost::bind(boost::bind(DPC::Print1,&x, 2), &t));
 t.async_wait(boost::bind(boost::bind(Component::Method1, &y, 10,
boost::bind (DPC::Print1, &x, 2)), &t));
 //t.async_wait(boost::bind(Component::Method1, &y, 10, boost::bind
(DPC::Print1, &x, 2), &t));

 d.run();
}

Compilation error log

Compiling...

TestTimer.cpp

Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately

Assuming _WIN32_WINNT=0x0500 (i.e. Windows 2000 target)

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::dm<R,T>,_bi::list_av_1<A1>::type>
boost::bind(R T::* ,A1)' : expects 2 arguments - 4 provided

t:\Projects\CodeGenericLibs\Boost\boost_1_33_1\boost\bind.hpp(1616) : see
declaration of 'boost::bind'

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,_bi::list_av_9<A1,A2,A3,A4,A5,A6,A7,A8,A9>::type>
boost::bind(R (__thiscall T::* )(B1,B2,B3,B4,B5,B6,B7,B8)
const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 4 provided

t:\Projects\CodeGenericLibs\Boost\boost_1_33_1\boost\bind\bind_mf_cc.hpp(222)
: see declaration of 'boost::bind'

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::mf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,_bi::list_av_9<A1,A2,A3,A4,A5,A6,A7,A8,A9>::type>
boost::bind(R (__thiscall T::*
)(B1,B2,B3,B4,B5,B6,B7,B8),A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10
arguments - 4 provided

t:\Projects\CodeGenericLibs\Boost\boost_1_33_1\boost\bind\bind_mf_cc.hpp(211)
: see declaration of 'boost::bind'

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::cmf7<R,T,B1,B2,B3,B4,B5,B6,B7>,_bi::list_av_8<A1,A2,A3,A4,A5,A6,A7,A8>::type>
boost::bind(R (__thiscall T::* )(B1,B2,B3,B4,B5,B6,B7)
const,A1,A2,A3,A4,A5,A6,A7,A8)' : expects 9 arguments - 4 provided

t:\Projects\CodeGenericLibs\Boost\boost_1_33_1\boost\bind\bind_mf_cc.hpp(198)
: see declaration of 'boost::bind'

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::mf7<R,T,B1,B2,B3,B4,B5,B6,B7>,_bi::list_av_8<A1,A2,A3,A4,A5,A6,A7,A8>::type>
boost::bind(R (__thiscall T::*
)(B1,B2,B3,B4,B5,B6,B7),A1,A2,A3,A4,A5,A6,A7,A8)' : expects 9 arguments - 4
provided

t:\Projects\CodeGenericLibs\Boost\boost_1_33_1\boost\bind\bind_mf_cc.hpp(187)
: see declaration of 'boost::bind'

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::cmf6<R,T,B1,B2,B3,B4,B5,B6>,_bi::list_av_7<A1,A2,A3,A4,A5,A6,A7>::type>
boost::bind(R (__thiscall T::* )(B1,B2,B3,B4,B5,B6)
const,A1,A2,A3,A4,A5,A6,A7)' : expects 8 arguments - 4 provided

t:\Projects\CodeGenericLibs\Boost\boost_1_33_1\boost\bind\bind_mf_cc.hpp(174)
: see declaration of 'boost::bind'

t:\Projects\FEI\CODE\Service\TimerService\utests\TestTimer1\TestTimer.cpp(42)
: error C2780:
'boost::_bi::bind_t<R,boost::_mfi::mf6<R,T,B1,B2,B3,B4,B5,B6>,_bi::list_av_7<A1,A2,A3,A4,A5,A6,A7>::type>
boost::bind(R (__thiscall T::* )(B1,B2,B3,B4,B5,B6),A1,A2,A3,A4,A5,A6,A7)' :
expects 8 arguments - 4 provided

...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk