When using std::bind, I was able to bind data members in VS2010 by passing a pointer or an iterator rather than the object itself. However, it no longer seems to work in VS2012:
#include <vector>
#include <utility>
#include <iostream>
#include <functional>
using namespace std;
int main()
{
vector<pair<string, int>> v;
v.push_back(make_pair("abc", 10));
auto f = bind(&pair<string, int>::second, v.begin());
int res = f();
cout << res << endl;
return 0;
}
GCC also compiles & runs this code fine, but VS2012 gives me an error:
error C2440: 'initializing' : cannot convert from 'std::_Do_call_ret<_Forced,_Ret,_Funx,_Btuple,_Ftuple>::type' to 'int'
1> with
1> [
1> _Forced=false,
1> _Ret=void,
1> _Funx=std::_Pmd_wrap<int std::pair<std::string,int>::* ,int,std::pair<std::string,int>>,
1> _Btuple=std::tuple<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::pair<std::string,int>>>>>,
1> _Ftuple=std::tuple<>
1> ]
1> Expressions of type void cannot be converted to other types
Note that if I pass an std::pair instance instead of an iterator or a pointer to it, then VS2012 is happy.
What is the problem here?