目前,当我一直在调用我的getFunction方法时,我得到了令人讨厌的崩溃。我的程序编译得很好,但是当我运行并调用此函数时,出现“Debug Assertion Failed!”,“Expression:vector subscript out of range”。不知道如何处理这个问题,因为我几年来一直没有在C++上做太多工作。C++ unorderedmap vector下标超出范围
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;
}
任何帮助,将不胜感激。
你在使用迭代器吗?因为如果你是,我没有看到你的代码中的任何东西。 – 2013-03-16 04:06:58
不,我没有使用任何迭代器。 – robbert229 2013-03-16 04:40:14
如果你使用std :: unordered_map,迭代器会让它变得更容易。下面是一个例子:http://www.cplusplus.com/reference/unordered_map/unordered_map/find/ – 2013-03-16 04:44:51