problem with bind and non-member function

Hi there, I'm using MSVC 7.1 and cannot get the following program to compile. I have tried the mailing list but couldn't find anything related. I'm sure it's a trivial problem but I cannot see right now. Anyone any idea? using namespace std; using namespace boost; struct a {}; struct b {}; void foo( string& s, a ) {} void foo( string& s, b ) {} int _tmain(int argc, _TCHAR* argv[]) { string str( "Hello" ); bind( static_cast<void(*)(string&, a )>( &foo ), ( ref( str ), a() )); return 0; } The error message is: c:\boost\boost\bind.hpp(63) : error C2825: 'F::result_type': cannot form a qualified name c:\boost\boost\bind\bind_template.hpp(15) : see reference to class template instantiation 'boost::_bi::result_traits<R,F>' being compiled with [ R=boost::_bi::unspecified, F=void (__cdecl *)(std::string &,a) ] test.cpp(18) : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' being compiled with [ R=boost::_bi::unspecified, F=void (__cdecl *)(std::string &,a), L=boost::_bi::list1<boost::_bi::list_av_1<a>::B1> ] c:\boost\boost\bind.hpp(63) : error C2039: 'result_type' : is not a member of 'operator``global namespace''' c:\boost\boost\bind.hpp(63) : error C2146: syntax error : missing ';' before identifier 'type' c:\boost\boost\bind.hpp(63) : error C2955: 'boost::_bi::type' : use of class template requires template argument list c:\boost\boost\bind.hpp(112) : see declaration of 'boost::_bi::type' c:\boost\boost\bind.hpp(63) : fatal error C1903: unable to recover from previous error(s); stopping compilation

Thanks Peter, it needs to be: using namespace std; using namespace boost; struct a {}; struct b {}; void foo( string& s, a ) {} void foo( string& s, b ) {} void two( int, int ) {} int _tmain(int argc, _TCHAR* argv[]) { string str( "Hello" ); bind( static_cast<void(*)(string&, a )>( &foo ), _1, _2)( ref( str ) , a() ); return 0; } On 3/9/07, Peter Dimov <pdimov@mmltd.net> wrote:
Christian Henning wrote:
bind( static_cast<void(*)(string&, a )>( &foo ), ( ref( str ), a() ));
The (x, y) expression returns y. In your case (ref(str), a()) is equivalent to just a().
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Christian Henning wrote:
Thanks Peter, it needs to be:
using namespace std; using namespace boost;
struct a {}; struct b {};
void foo( string& s, a ) {} void foo( string& s, b ) {}
void two( int, int ) {}
int _tmain(int argc, _TCHAR* argv[]) { string str( "Hello" ); bind( static_cast<void(*)(string&, a )>( &foo ), _1, _2)( ref( str ) , a() );
return 0; }
Are you still having problems with it? This works for me with the latest CVS; you may need to define an object of type 'a' since earlier versions of bind didn't accept rvalues such as a().

Thanks Peter, yes it works for me. Thanks On 3/9/07, Peter Dimov <pdimov@mmltd.net> wrote:
Christian Henning wrote:
Thanks Peter, it needs to be:
using namespace std; using namespace boost;
struct a {}; struct b {};
void foo( string& s, a ) {} void foo( string& s, b ) {}
void two( int, int ) {}
int _tmain(int argc, _TCHAR* argv[]) { string str( "Hello" ); bind( static_cast<void(*)(string&, a )>( &foo ), _1, _2)( ref( str ) , a() );
return 0; }
Are you still having problems with it? This works for me with the latest CVS; you may need to define an object of type 'a' since earlier versions of bind didn't accept rvalues such as a().
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Christian Henning
-
Peter Dimov