|
Boost Users : |
Subject: [Boost-users] Example program that fails to compile (boost::bind and boost::function called for collection)
From: Archie14 (admin_at_[hidden])
Date: 2009-01-27 14:21:48
Below is a a test program with the purpose of calling member function for each
element of the collection. Argument of this member function is a
boost::function.
I put compilation error after the source code.
Any help will be greatly appreciated.
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
typedef boost::function<void (int, int, const char*) > delegate;
class A : public boost::noncopyable
{
public:
commandhandler(delegate& f) {}
};
template <typename C> class Acoll
{
typedef boost::ptr_vector<C> ptr_container;
ptr_container m_data;
public:
typedef C CLIENT;
ptr_container& operator() (){return m_data;}
};
template <typename CLIENTS> class Test
{
CLIENTS& m_clients;
public:
delegate dosomething;
Test(CLIENTS& val) : m_clients(val) {}
void run()
{
std::for_each(m_clients().begin(), m_clients().end(),
boost::bind(&CLIENTS::CLIENT::commandhandler,
boost::ref(dosomething), _1 ));
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Acoll<A> coll;
Test<Acoll<A> > test(coll);
test.run();
return 0;
}
Error:
1>e:\libraries\boost\boost_1_37_0\boost\bind.hpp(292) : error C2664: 'R
boost::_mfi::mf1<R,T,A1>::operator ()<boost::function<Signature>>(const U &,A1)
const' : cannot convert parameter 2 from 'A' to 'boost::function<Signature> '
1> with
1> [
1> R=void,
1> T=A,
1> A1=delegate &,
1> Signature=void (int,int,const char *),
1> U=delegate
1> ]
1> and
1> [
1> Signature=void (int,int,const char *)
1> ]
1> e:\libraries\boost\boost_1_37_0\boost\bind\bind_template.hpp(32) :
see reference to function template instantiation 'void
boost::_bi::list2<A1,A2>::operator ()<F,boost::_bi::list1<A
&>>(boost::_bi::type<T>,F &,A &,int)' being compiled
1> with
1> [
1> A1=boost::reference_wrapper<delegate>,
1> A2=boost::arg<1>,
1> F=boost::_mfi::mf1<void,A,delegate &>,
1> T=void,
1> A=boost::_bi::list1<A &>
1> ]
1> e:\program files\microsoft visual studio 9.0\vc\include\algorithm(29)
: see reference to function template instantiation 'void
boost::_bi::bind_t<R,F,L>::operator ()<T>(A1 &)' being compiled
1> with
1> [
1> R=void,
1> F=boost::_mfi::mf1<void,A,delegate &>,
1>
L=boost::_bi::list2<boost::reference_wrapper<delegate>,boost::arg<1>>,
1> T=A,
1> A1=A
1> ]
1> c:\test\t458\t458\t458.cpp(39) : see reference to function template
instantiation '_Fn1
std::for_each<boost::void_ptr_iterator<VoidIter,T>,boost::_bi::bind_t<R,F,L>>(_
InIt,_InIt,_Fn1)' being compiled
1> with
1> [
1> _Fn1=boost::_bi::bind_t<void,boost::_mfi::mf1<void,A,delegate
&>,boost::_bi::list2<boost::reference_wrapper<delegate>,boost::arg<1>>>,
1> VoidIter=std::_Vector_iterator<void *,std::allocator<void *>>,
1> T=A,
1> R=void,
1> F=boost::_mfi::mf1<void,A,delegate &>,
1>
L=boost::_bi::list2<boost::reference_wrapper<delegate>,boost::arg<1>>,
1> _InIt=boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,A>
1> ]
1> c:\test\t458\t458\t458.cpp(37) : while compiling class template
member function 'void Test<CLIENTS>::run(void)'
1> with
1> [
1> CLIENTS=Acoll<A>
1> ]
1> c:\test\t458\t458\t458.cpp(47) : see reference to class template
instantiation 'Test<CLIENTS>' being compiled
1> with
1> [
1> CLIENTS=Acoll<A>
1> ]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net