0

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.

robbert229
  • 464
  • 5
  • 12
  • Are you using iterators? Because if you are, I am not seeing anything in your code. –  Mar 16 '13 at 04:06
  • no, I am not using any iterators. – robbert229 Mar 16 '13 at 04:40
  • 1
    If you are using std::unordered_map, iterator would make it ***much*** easier. Here is an example: http://www.cplusplus.com/reference/unordered_map/unordered_map/find/ –  Mar 16 '13 at 04:44

1 Answers1

1

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.

Adnan Akbar
  • 718
  • 6
  • 16