Thanks Daniel, my mistake.
On 3/26/07, Daniel
Date: Mon, 26 Mar 2007 11:24:08 -0400 From: "Christian Henning"
Subject: [Boost-users] [bind] static array vs. pointer vector To: boost-users@lists.boost.org Message-ID: <949801310703260824n31c76204pcd63bb686169e15c@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi there, I have posted this question last Friday, already. But maybe my example was too confusing. Here is a more simple example. Basically, I don't see what the big difference is when using boost::bind with a pointer vector ( std::vector
) and a static array of info. Please consider the following code:
#include <string> #include <algorithm> #include <functional> #include <vector>
#include
using namespace std; using namespace boost;
struct info { int a; string s; };
static info table[] = { { 16, "Hello" }, { 18, "Moin" } };
string& get_s( info* p ) { return p->s; }
int _tmain(int argc, _TCHAR* argv[]) { { vector
v; find_if( v.begin(), v.end() , bind( equal_to<string>() , bind( &get_s, _1 ) , "Moin" )); } { find_if( &table[0], &table[0] + 2 , bind( equal_to<string>() , bind( &get_s, _1 ) , "Moin" ));
} }
The second find_if wont complie using MSVC 7.1. The errors are:
c:\boost\boost\bind.hpp(219) : error C2664: 'std::string &(info *)' : cannot convert parameter 1 from 'info' to 'info *' [snip]
Any ideas?
Christian
In 1st case, when you dereference vector
iterator, you will get info* pointer. But in 2nd case, your iterator is info* pointer, so you get info object when you dereference it. This is also mentioned at beginning of error message - "cannot convert parameter 1 from 'info' to 'info *'". Therefore you should change your get_s() function to accept info (or info&), or your binding expression to convert info to info*. Daniel
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users