【发布时间】:2015-07-18 09:54:40
【问题描述】:
我想在 C++ 中动态分配指向 unordered_map 的指针数组。 std::unordered 映射已被 typedef 为“字典”。
dict_array= ( dictionary **) calloc(input_size, sizeof(dictionary*));
现在我想访问单个哈希图,对于每个单独的哈希图(mydict),我想使用某个键访问值。如下:
for (int i=0; i< input_size, i++){
dictionary *mydict= dict_array[i];
mydict[some_key]++; /*access the value against 'some_key' and increment it*/
}
但是上面这行根据键访问值会产生编译错误。访问它的正确方法是什么?
【问题讨论】:
-
您是在创建指向标准容器的指针吗?
-
你为什么使用
calloc?在 C++ 中任何提及“动态数组”都会导致强制性的“你为什么不使用std::vector”?
标签: c++ pointers hashmap dynamic-arrays unordered-map