当调用unordered_map的函数的时候,会出现如下问题:

unordered_map 遇到 vector subscript out of range 的错误提示

使用linux运行则会提示
float exeption(core dump)


原因

遇到vector subscript out of range 很可能是因为 unordered_map 没有被正确地初始化推荐使用new来初始化,减少一些版本兼容的问题。

例子

例如:

使用 calloc () 初始化unordered_map 的对象,会出现错误:

dyn_tbl_t* ret = (dyn_tbl_t*)calloc(1, sizeof(dyn_tbl_t));

改为

dyn_tbl_t* ret = new dyn_tbl_t;

即可正常运行。

相关文章:

猜你喜欢
相关资源
相似解决方案