objected映射到unordered_map,是系统初始化的吗?
objected mapped to in unordered_map, is it initialized by the system?
使用unordered_map映射到结构时,想知道映射到的对象是否被系统初始化。我在 g++ 4.7.3 中使用 Ubuntu 12.04 64 位。谢谢。
#include <iostream>
#include <unordered_map>
struct strDum {
uint a[3];
int id;
};
int main (int argc, char *argv[])
{
int i;
char cmd[100];
std::unordered_map<std::string,strDum> mymap;
mymap["john"].a[0] = 10;
mymap["john"].a[1] = 20;
mymap["john"].a[2] = 30;
printf("%d\n", mymap[argv[1]].a[1]);
return 0;
}
您正在以下几行std::unordered_map
mymap
中初始化
mymap["john"].a[0] = 10;
mymap["john"].a[1] = 20;
mymap["john"].a[2] = 30;
如果在使用std::unordered_map::operator[], the mapped value is value-initialized时执行插入。
Returns a reference to the value that is mapped to a key equivalent to
key, performing an insertion if such key does not already exist.
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.
使用unordered_map映射到结构时,想知道映射到的对象是否被系统初始化。我在 g++ 4.7.3 中使用 Ubuntu 12.04 64 位。谢谢。
#include <iostream>
#include <unordered_map>
struct strDum {
uint a[3];
int id;
};
int main (int argc, char *argv[])
{
int i;
char cmd[100];
std::unordered_map<std::string,strDum> mymap;
mymap["john"].a[0] = 10;
mymap["john"].a[1] = 20;
mymap["john"].a[2] = 30;
printf("%d\n", mymap[argv[1]].a[1]);
return 0;
}
您正在以下几行std::unordered_map
mymap
中初始化
mymap["john"].a[0] = 10;
mymap["john"].a[1] = 20;
mymap["john"].a[2] = 30;
如果在使用std::unordered_map::operator[], the mapped value is value-initialized时执行插入。
Returns a reference to the value that is mapped to a key equivalent to key, performing an insertion if such key does not already exist.
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.