P
P G
I hope this is on topic here. I have a problem compiling a simple
example of the use of boost::bind. Please take a look at the program
below.
/**************************************************************************/
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <memory>
using namespace boost;
struct X{
void f()
{
std::cout<<"Bind Test\n";
}
};
int main()
{
X x;
shared_ptr<X> p(new X());
bind(&X::f, p)(); //fine
bind(&X::f, &x)(); //fine
bind(&X::f, ref(x))(); //fine
bind(&X::f, x)(); //will not compile
return 0;
}
/*********************************************************************/
I can bind the member function ponter to a smart pointer, to an
ordinary pointer, or to a reference wrapper but I get compile errors
in the last case.
The documentation suggests that bind should make a copy of x. I have
used two compilers (MSVC 2003 and gcc 3.2) and both of them barf on
the last invocation of bind.
The GCC error message is:
c:/boost/boost/bind/mem_fn_template.hpp: In member function `R
boost::_mfi::mf0<R, T>::call(U&, const T*) const [with U = const X,
R =
void, T = X]':
c:/boost/boost/bind/mem_fn_template.hpp:51: instantiated from `R
boost::_mfi::
mf0<R, T>:perator()(U&) const [with U = const X, R = void, T = X]'
c:/boost/boost/bind.hpp:186: instantiated from `R
boost::_bi::list1<A1>:pera
tor()(boost::_bi::type<R>, F, A&) const [with R = void, F =
boost::_mfi::mf0<voi
d, X>, A = boost::_bi::list0, A1 = boost::_bi::value<X>]'
c:/boost/boost/bind/bind_template.hpp:21: instantiated from
`boost::_bi::resul
t_traits<R, F>::type boost::_bi::bind_t<R, F, L>:perator()() [with R
= void, F
= boost::_mfi::mf0<void, X>, L =
boost::_bi::list1<boost::_bi::value<X> >]'
b.cpp:36: instantiated from here
c:/boost/boost/bind/mem_fn_template.hpp:32: invalid conversion from
`const X*'
to `X*'
Has anybody encountered this?
Thanks.
example of the use of boost::bind. Please take a look at the program
below.
/**************************************************************************/
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <memory>
using namespace boost;
struct X{
void f()
{
std::cout<<"Bind Test\n";
}
};
int main()
{
X x;
shared_ptr<X> p(new X());
bind(&X::f, p)(); //fine
bind(&X::f, &x)(); //fine
bind(&X::f, ref(x))(); //fine
bind(&X::f, x)(); //will not compile
return 0;
}
/*********************************************************************/
I can bind the member function ponter to a smart pointer, to an
ordinary pointer, or to a reference wrapper but I get compile errors
in the last case.
The documentation suggests that bind should make a copy of x. I have
used two compilers (MSVC 2003 and gcc 3.2) and both of them barf on
the last invocation of bind.
The GCC error message is:
c:/boost/boost/bind/mem_fn_template.hpp: In member function `R
boost::_mfi::mf0<R, T>::call(U&, const T*) const [with U = const X,
R =
void, T = X]':
c:/boost/boost/bind/mem_fn_template.hpp:51: instantiated from `R
boost::_mfi::
mf0<R, T>:perator()(U&) const [with U = const X, R = void, T = X]'
c:/boost/boost/bind.hpp:186: instantiated from `R
boost::_bi::list1<A1>:pera
tor()(boost::_bi::type<R>, F, A&) const [with R = void, F =
boost::_mfi::mf0<voi
d, X>, A = boost::_bi::list0, A1 = boost::_bi::value<X>]'
c:/boost/boost/bind/bind_template.hpp:21: instantiated from
`boost::_bi::resul
t_traits<R, F>::type boost::_bi::bind_t<R, F, L>:perator()() [with R
= void, F
= boost::_mfi::mf0<void, X>, L =
boost::_bi::list1<boost::_bi::value<X> >]'
b.cpp:36: instantiated from here
c:/boost/boost/bind/mem_fn_template.hpp:32: invalid conversion from
`const X*'
to `X*'
Has anybody encountered this?
Thanks.