以下兩種情況有什麼區別?boost :: bind與地圖綁定,綁定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);
第一個示例工作正常,但第二個示例在綁定完成時無法編譯。我已經看了看文件stl_map.h
和value_type
定義如下:
typedef std::pair<const _Key, _Tp> 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
謝謝!
沒錯!我沒有意識到'const' Gracias! – user1192525 2012-02-26 17:08:52