Why is the [] operator of C++ Map calling default constructor of mapped-value? [duplicate]
问题 This question already has answers here : Why does the C++ map type argument require an empty constructor when using []? (5 answers) Closed 2 years ago . I compiled the following code with g++, the construct function A() will be called when executing the line: m["1"] Why is this happening? I don't see any necessarily of calling the constructor here. struct A { int mem; A(int arg){} A(){} }; int main() { unordered_map<string, A> m; m["1"]; // will call A(), but why? m.find("1")->second; // will