Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
STL コンテナーを使用する場合、デフォルトのアロケーターによって割り当てられた int がゼロ化されているかどうかがわかりません。次のコードは、質問に対して「はい」を示します。
#include <map> #include <iostream> int main() { using namespace std; map<int, int> m; cout << m[1234] << endl; }
これを確認した文書はないので、私はそれを当然のこととは考えていません。
の実装内でstd::map::operator[]、要素がインデックスで見つからない場合、新しい要素が挿入されて返されることがわかります。
std::map::operator[]
ReturnValue = this->insert(where, make_pair(key_value, mapped_type()));
mapped_typeあなたの場合、2番目のタイプはどこですかint。はい、0として挿入されるため、デフォルトで に初期化されmapped_type()ます。
mapped_type
int
0
mapped_type()