Why doesn't a call to std::map::operator[] compile for a value type without default constructor? [duplicate]
问题 This question already has answers here : Default constructor of the structure for correct std::map behaviour (2 answers) Closed 6 months ago . Consider the following class MyStruct : struct MyStruct { int x; int y; MyStruct(int i, int j): x(i), y(j) { } }; Note that MyStruct doesn't have a default destructor. The assignment m["AAAA"] = MyStruct(1, 1) in the code below doesn't compile: int main(int, char**) { map<string, MyStruct> m; m["AAAA"] = MyStruct(1, 1); return 0; } Why I need default