[boost] boost::bind - simple test case does not work...

2003-03-03 Thread Marc Jacobs
While I've successfully used boost::bind before, I cannot seem to get this
simple test case to work.

#include boost/bind.hpp
#include iostream

using namespace boost;
using namespace std;

struct X
{
void f( int i )
{
cout  i  \n;
}
};

int main( int argc, char * argv[] )
{
X x;

bind( X::f, x, 6 )(); // works
bind( X::f, x, _1 )( 6 ); // error!

return 0;
}

It fails during compilation with the following error messages:
callback.cpp: In function `int main (int, char **)':
callback.cpp:20: no match for call to `(boost::_bi::bind_tvoid,
boost::_mfi::mf1void, X, int, boost::_bi::list2boost::_bi::valueX
*, boost::arg1  ) (int)'
/usr/local/include/boost/bind/bind_template.hpp:19: candidates are: typename
boost::_bi::result_traitsR, F::type boost::_bi::bind_tR, F,
L::operator() () [with R = void, F =
boost::_mfi::mf1void, X, int, L = boost::_bi::list2boost::_bi::valueX
*, boost::arg1 ]
/usr/local/include/boost/bind/bind_template.hpp:25: typename
boost::_bi::result_traitsR, F::type boost::_bi::bind_tR, F,
L::operator() () const [with R = void,
F = boost::_mfi::mf1void, X, int, L =
boost::_bi::list2boost::_bi::valueX *, boost::arg1 ]
/usr/local/include/boost/bind/bind_template.hpp:31: typename
boost::_bi::result_traitsR, F::type boost::_bi::bind_tR, F,
L::operator() (A1 ) [with A1 = int, R
= void, F = boost::_mfi::mf1void, X, int, L =
boost::_bi::list2boost::_bi::valueX *, boost::arg1
]
/usr/local/include/boost/bind/bind_template.hpp:37: typename
boost::_bi::result_traitsR, F::type boost::_bi::bind_tR, F,
L::operator() (A1 ) const [with A1 =
int, R = void, F = boost::_mfi::mf1void, X, int, L =
boost::_bi::list2boost::_bi::valueX *,
boost::arg1 ]

Suggestions?
Marc



___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] boost::bind - simple test case does not work...

2003-03-03 Thread Douglas Gregor
On Monday 03 March 2003 05:03 pm, Marc Jacobs wrote:
 bind( X::f, x, _1 )( 6 ); // error!

You can't pass rvalues to boost::bind function objects, because of the 
forwarding problem in C++. If you use this it should work:

  int i = 6;
  bind( X::f, x, _1 )( i );

There's a good description of the forwarding problem here:
  http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm

Doug
___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost