当调用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;

即可正常运行。

相关文章:

  • 2022-12-23
  • 2021-05-31
  • 2018-08-22
  • 2021-06-16
  • 2022-01-06
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-13
  • 2021-08-30
  • 2021-11-25
  • 2021-09-26
  • 2021-09-04
  • 2021-07-29
相关资源
相似解决方案