c ++ unorderedmap向量下标超出范围 [英] c++ unorderedmap vector subscript out of range
问题描述
目前,当我一直在调用我的getFunction方法,我得到讨厌的崩溃。我的程序编译得很好,但是当我运行并调用这个函数时,我得到Debug Assertion Failed!,Expression:vector subscript out of range。不知道如何处理这个,因为我没有做过很多在c + +几年。
Currently when I have been calling my getFunction method I am getting nasty crash. My program compiles fine, but when I run and call this function, I get "Debug Assertion Failed!", "Expression: vector subscript out of range". Not sure how to deal with this as I haven't been doing much in c++ for a few years.
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;
}
任何帮助将不胜感激。
Any help would be appreciated.
推荐答案
请避免char * with std :: unordered_map使用正确的std :: string, char *作为指针类型,这可能会导致问题,除非你已经定义了std :: hash。
Please avoid char* with std::unordered_map use proper std::string and it should be fine. char* is taken as pointer type and which might cause an issue unless you have defined std::hash for it.
这篇关于c ++ unorderedmap向量下标超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!