|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-03-13 20:05:02
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<R,F,L>'
> 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
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