次の2つのケースの違いは何ですか?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);
最初の例はうまくいきますが、2番目の例はバインディングが完了してもコンパイルされません。
typedef std::pair<const _Key, _Tp> value_type;
私は違いが表示されていない:私は次のように定義されたファイルstl_map.h
を見てvalue_type
ています。誰かが私に知らせることができ、2番目の例がコンパイルされない理由を伝えることができて感謝します。
コンパイルエラーメッセージは次のとおりです。事前に
.../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