c++ unordered_map vector 下标超出范围

标签 c++ vector range runtime-error unordered-map

目前,当我调用我的 getFunction 方法时,我遇到了严重的崩溃。我的程序编译得很好,但是当我运行并调用这个函数时,我得到“调试断言失败!”、“表达式: vector 下标超出范围”。不确定如何处理这个问题,因为几年来我在 C++ 中没有做太多事情。

void* PluginMap::getFunction(char* pguid, char* fname){
    if(plugin_map.size()>0 && plugin_map.find(pguid)!=plugin_map.end())
    { 
        //plugin_map is an unorderedmap that is defined elsewhere.
        MicroMap* mm = &plugin_map[pguid];
        if((*mm).find(fname)!=(*mm).end())
        {
            //MicroMap is an unorderedmap that goes in plugin_map, and contains void*
            return (*mm)[fname];
        }
    }
    return 0;
}

如有任何帮助,我们将不胜感激。

最佳答案

请避免使用带有 std::unordered_map 的 char*,使用正确的 std::string 应该没问题。 char* 被视为指针类型,除非您为其定义了 std::hash ,否则可能会导致问题。

关于c++ unordered_map vector 下标超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15445397/

相关文章:

c++ - C++ 中不同 vector 之间没有线程安全?

c++函数返回 vector 中的最小正整数

Python - scapy sniff() 具有端口范围的过滤器

c++ - 如何处理错误的数据类型输入

c++ - Qt:Qt 类与标准 C++

c++ - 模板参数的引用变量的问题

python - 如何修复错误 :'range' object is not callable in python3.6

c++ - Metro C++/XAML ListView 捕捉项

使用 vector 的 Java 警告 : unchecked call to add(E)

mysql - SQL SELECT 查询列中的多个值和范围