<分区>
由于缺少索引而插入到映射中的指针是否始终为 NULL?
std::map<int, Foo*> myMap;
Foo* myFoo = myMap[0];
myFoo 是否保证为 NULL?
标签 c++
<分区>
由于缺少索引而插入到映射中的指针是否始终为 NULL?
std::map<int, Foo*> myMap;
Foo* myFoo = myMap[0];
myFoo 是否保证为 NULL?
最佳答案
来自 cppreference :
If an insertion is performed, the mapped value is value-initialized (default-constructed for class types, zero-initialized otherwise) and a reference to it is returned
所以是的,这保证为 NULL
。
关于c++ - 使用 operator[] 时映射中的默认指针值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29758339/