目前,當我一直在調用我的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