私はVS2015で以下のコードをコンパイルしようとしています。私のstd :: mapの最初のバージョンはコンパイルされていますが、秒版はコンパイルされません。std :: map find()エラーを返す
std::map<std::string, DataDictionary> _p1;
DataDictionary DD = _p1.find["1"]; //ERROR
I:私は、私は同じエラーを取得しています、私のstd ::マップを変更し、次を使用することを決定した場合であっても...私は私がここで間違ってやっているのか分から
std::map<int, std::string> _p;
typedef std::pair<int, std::string> _q;
_p.insert(_q(0, "Football0"));
_p.insert(_q(1, "Football1"));
std::string str = _p[1]; //OK...compiles and executes, no error, str = "Football1" as expected
std::map<int, DataDictionary> _p1;
typedef std::pair<int, DataDictionary> _q1;
DataDictionary dd1;
dd1.i = 0;
dd1.version = "ver1";
_p1.insert(_q1(0, dd1));
DataDictionary dd2;
dd2.i = 0;
dd2.version = "ver2";
_p1.insert(_q1(1, dd2));
DataDictionary DD = _p1.find[1]; //error C3867: 'std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::find': non-standard syntax; use '&' to create a pointer to member
を聞かせてください。 DataDictionary構造体でマップを使用しようとしていて、要素にアクセスするには_p1.find["1"]
構文を使用してください。このアプローチはイテレータをマップに宣言するよりも高速であると仮定しているので、find()を使用してください。助けてください。おかげで、
[ 'のstd ::マップ::見つける()'](http://en.cppreference.com/w/cpp/container/map/find)あなたはそれがないと思うタイプを返しません。 –
あなたは角括弧を使用することができ、[*添字演算子*](http://en.cppreference.com/w/cpp/container/map/operator_at)、または[ 'find'](HTTP://en.cppreference .com/w/cpp/container/map/find)。これは通常の関数呼び出しであり、丸括弧を使用します。あなたは両方を混ぜています。 – BoBTFish
ご返信ありがとうございます。しかし、注意してくださいコード - std :: string str = _p [1];実際に働いています。 std :: stringの代わりにstructを返そうとしているときだけ、コンパイルエラーが発生します – XMarshall