다음 두 경우의 차이점은 무엇입니까?boost :: bind with maps, 바인딩 std :: pair와 std :: map :: value_type의 차이점은 무엇입니까?
std::pair<int,std::string> example_1 (std::make_pair (1,"foo"));
int value_1 = boost::bind (&std::pair<int,std::string>::first,_1) (example_1);
std::map<int,std::string>::value_type example_2 (std::make_pair (2,"boo"));
int value_2 = boost::bind (&std::pair<int,std::string>::first,_1) (example_2);
첫 번째 예제는 제대로 작동하지만 바인딩이 완료되면 두 번째 예제는 컴파일되지 않습니다.
typedef std::pair<const _Key, _Tp> value_type;
나는 그 차이를 볼 수 없습니다 다음과 같이 나는 파일 stl_map.h
에보고하고 value_type
가 정의됩니다. 나는 두 번째 예제가 컴파일되지 않는 이유와 그 이유를 누군가에게 알려주는 것에 감사 할 것입니다.
컴파일 에러 메시지는 다음과 같습니다 사전에
.../include/boost/bind/mem_fn.hpp:333:36: error: no matching function for call to ‘get_pointer(const std::pair<const int, std::basic_string<char> >&)’
make: *** [main.o] Error 1
감사합니다! 당신이 사용하고있는 쌍 (귀하의 경우 일반 int
)를하지 않는 반면
맞아요! 나는 'const'를 깨닫지 못했다. Gracias! – user1192525