
AMDG Boris wrote:
Can anyone explain to me why VC++ 2008 refuses to compile this code:
void empty() { }
template <class T> void foo(T t) { // error C2664: 'void (T)' : cannot convert // parameter 1 from 'void' to 'boost::_bi::bind_t
' boost::bind(bar<T>, t)(); // This one works though: boost::bind(bar<T>, _1)(t); }
template <class T> void bar(T t) { t(); }
int main() { foo(boost::bind(empty)); }
Is this a problem with the VC++ 2008 compiler or am I trying to do something which isn't supported by Boost.Bind?
The expression which you are creating in multiple stages is boost::bind(bar<T>, boost::bind(empty))() Bind tries to evaluates this as bar<T>(empty()) rather than what you intended: bar<T>(empty) Try: foo(boost::protect(boost::bind(empty))); To prevent composition. In Christ, Steven Watanabe