Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <functional>
#include <boost/bind.hpp>
class A
{
public:
	A(){}
	~A(){}
	template<typename _Handler>
	void call_handler(_Handler handler)
	{
		handler();
	}
};

class B
{
public:
	template<typename _Handler>
	void call_handler(_Handler handler)
	{

	}
	template<typename _Handler>
	void run(_Handler handler)
	{
		m_a.call_handler(boost::bind(&B::call_handler<_Handler>, this, handler));
		//only can use boost::bind here
	}
	A m_a;
};
class Test
{
public:
	void handler()
	{

	}
};

int main()
{
	B b;
	Test t;
	b.run(boost::bind(&Test::handler,&t));//only can use std::bind here
}

this is my little test code above.
I am confused that I only can use bind in the specific order...see note above
if I change std::bind to boost::bind ,then compiler failed,vice versa.
tested with:
gcc 4.9.2 for cygwin with option:
g++ -std=c++11 -fdiagnostics-color=always -fdiagnostics-show-location=every-line -I"/cygdrive/e/opensource libs/boost" main.cpp
msvc 12.0(visual studio 2013 with update4) with default option.


gcc diagnostic messages:
In file included from /cygdrive/e/opensource libs/boost/boost/bind.hpp:22:0,
from main.cpp:3:
/cygdrive/e/opensource libs/boost/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list2<a1,>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf1<void,>, boost::_bi::list1<boost::_bi::value xmlns:boost="#unknown"><test*> > > >; A = boost::_bi::list0; A1 = boost::_bi::value<b*>; A2 = boost::_bi::bind_t<void,>, boost::_bi::list1<boost::_bi::value><test*> > >]’:
/cygdrive/e/opensource libs/boost/boost/bind/bind.hpp:893:50: required from ‘boost::_bi::bind_t<r,>::result_type boost::_bi::bind_t<r,>::operator()() [with R = void; F = boost::_mfi::mf1<void,>, boost::_bi::list1<boost::_bi::value><test*> > > >; L = boost::_bi::list2<boost::_bi::value><b*>, boost::_bi::bind_t<void,>, boost::_bi::list1<boost::_bi::value><test*> > > >; boost::_bi::bind_t<r,>::result_type = void]’
main.cpp:12:11: required from ‘void A::call_handler(_Handler) [with _Handler = boost::_bi::bind_t<void,>, boost::_bi::list1<boost::_bi::value><test*> > > >, boost::_bi::list2<boost::_bi::value><b*>, boost::_bi::bind_t<void,>, boost::_bi::list1<boost::_bi::value><test*> > > > >]’
main.cpp:27:3: required from ‘void B::run(_Handler) [with _Handler = boost::_bi::bind_t<void,>, boost::_bi::list1<boost::_bi::value><test*> > >]’
main.cpp:44:38: required from here
/cygdrive/e/opensource libs/boost/boost/bind/bind.hpp:313:34: error: invalid use of void expression
unwrapper<f>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
^

msvc 12.0 diagnostic messages:
1>------ Build started: Project: scince_x32, Configuration: Debug Win32 ------
1> main.cpp
1>e:\opensource libs\boost\boost\bind\bind.hpp(313): error C2664: 'void boost::_mfi::mf1<void,b,_handler>::operator ()(T *,A1) const' : cannot convert argument 2 from 'void' to 'boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><t>>>'
1> with
1> [
1> _Handler=boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>
1> , T=B
1> , A1=boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>
1> ]
1> and
1> [
1> T=Test *
1> ]
1> Expressions of type void cannot be converted to other types
1> e:\opensource libs\boost\boost\bind\bind.hpp(893) : see reference to function template instantiation 'void boost::_bi::list2<boost::_bi::value><t>,boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>::operator ()<f,boost::_bi::list0>(boost::_bi::type<void>,F &,A &,int)' being compiled
1> with
1> [
1> T=B *
1> , F=boost::_mfi::mf1<void,b,boost::_bi::bind_t><void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>
1> , A=boost::_bi::list0
1> ]
1> e:\opensource libs\boost\boost\bind\bind.hpp(893) : see reference to function template instantiation 'void boost::_bi::list2<boost::_bi::value><t>,boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>::operator ()<f,boost::_bi::list0>(boost::_bi::type<void>,F &,A &,int)' being compiled
1> with
1> [
1> T=B *
1> , F=boost::_mfi::mf1<void,b,boost::_bi::bind_t><void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>
1> , A=boost::_bi::list0
1> ]
1> e:\opensource libs\boost\boost\bind\bind.hpp(891) : while compiling class template member function 'void boost::_bi::bind_t<void,boost::_mfi::mf1><void,b,_handler>,boost::_bi::list2<boost::_bi::value><t>,boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>>::operator ()(void)'
1> with
1> [
1> _Handler=boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>
1> , T=B *
1> ]
1> e:\c++program\scince_x32\scince_x32\main.cpp(12) : see reference to function template instantiation 'void boost::_bi::bind_t<void,boost::_mfi::mf1><void,b,_handler>,boost::_bi::list2<boost::_bi::value><t>,boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>>::operator ()(void)' being compiled
1> with
1> [
1> _Handler=boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>
1> , T=B *
1> ]
1> e:\c++program\scince_x32\scince_x32\main.cpp(27) : see reference to class template instantiation 'boost::_bi::bind_t<void,boost::_mfi::mf1><void,b,_handler>,boost::_bi::list2<boost::_bi::value><t>,boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>>>' being compiled
1> with
1> [
1> _Handler=boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>
1> , T=B *
1> ]
1> e:\c++program\scince_x32\scince_x32\main.cpp(44) : see reference to function template instantiation 'void B::run<boost::_bi::bind_t><void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><t>>>>(_Handler)' being compiled
1> with
1> [
1> T=Test *
1> , _Handler=boost::_bi::bind_t<void,boost::_mfi::mf0><void,test>,boost::_bi::list1<boost::_bi::value><test>>>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Posted
Updated 2-Jun-15 5:02am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900