   map
  is there a reason that map::find() would fail??it's giving me an error saying:"An unhandled exception of type 'System.NullReferenceException' occurred in Phyer Shooter.exeAdditional information: Object reference not set to an instance of an object."my map is defined as map<std::string, myType> and all i'm doing is testing Iter = map::find("somestring") and it's failing and giving me that error   
Quote:Iter = map::find("somestring") Do you mean = or ==?...std::map<std::string, myType>.find(std::string) can "fail" in the following ways:1> It can return map.end() if it can't find the std::string as a key in the map.2> If operator lessthan crashes/throws an exception, it can throw an exception.3> If you change the ordering of elements in a map without taking them out of the map and putting them back in, undefined behaviour can result.4> If your operator lessthan isn't "consistant", undefined behaviour can result.  (ie, if a<b but b<a, or a<b and b<c, but a is not less than c, etc).5> If you have memory corruption that screws up the std::map's memory, undefined behaviour can result.;  Type* Add(std::string RefName){Type *newType = new Type();std::map <std::string, Type*>::iteratorIter;std::stringstream ss;ss << RefName;Iter = m_MapList.find(ss.str()); // fails here   ;Quote:Original post by EvilKnuckles666Type* Add(std::string RefName){Type *newType = new Type();std::map <std::string, Type*>::iteratorIter;std::stringstream ss;ss << RefName;Iter = m_MapList.find(ss.str()); // fails hereDaymn.  :)  Ok, step 1, simplify, and test multiple simple cases.Change "Add" to:Type* Add(std::string RefName){  typedef std::map <std::string, Type*> mymap;  // the next set of code is an attempt to see what crashes.  // if the next set of code doesn't crash, then it has no side effects:  mymap map_test; // a stand alone temp map  map_test.find(RefName); // a failed search  mymap::iterator Iter1 = map_test.find(RefName); // a failed search with assign  map_test[RefName] = 0; // put something in the temp map  map_test.find(RefName); // a successful search  Iter1 = map_test.find(RefName); //  a successful search, with assign  m_MapList.find(RefName); // the search in the real map, but with no assignment  // Ok, and now we try what the original code did:  mymap::iteratorIter = m_MapList.find(RefName); // does this crash?  Type *newType = new Type();  // .. the rest of the function follows}Does it crash at the same spot, or earlier?  Does it not crash anymore?I removed the stringstream object because, honestly, it wasn't needed in the code you provided.;  i use the stringstream later on in the function for something elsebut the code you had failed when it got to:m_MapList.find(RefName); // the search in the real map, but with no assignmentwhat's that mean?   ;Quote:Original post by EvilKnuckles666i use the stringstream later on in the function for something elsebut the code you had failed when it got to:m_MapList.find(RefName); // the search in the real map, but with no assignmentwhat's that mean?Your std::map "m_MapList" has been corrupted somehow.A few ways it could have been corrupted:1> Did someone already delete the "this" object you are working on?2> Is your "this" pointer null?3> Random memory corruption.4> Someone changed one of the keys in the std::map on it.5> Something else!Possibility 3 4 and 5 are hard to track down.  So following the path of least resistance, let's examine your "this" pointer.What is the value of "this"?  (either look at it in the debugger, or use printf("0x%08x\n", this);)Is it null?  (if so, we have a solution!)What debugger are you using?  Does it mark deleted memory -- and is the memory pointed to by the "this" pointer deleted?Can you log all deletes of objects of the type causing the problem?  Do any of them match the "this" pointer that is being called with the crash?;  uhoh... how'd that happened?  when i viewed the "this" pointer, i looked at the value of the map<> template and it said it has an <undefined value>... how would that happen?   ;  The more important question is this:Why are you getting a System.NullReferenceException, which is a .NET Framework class, in your C++ project?Are you using C++/CLI?   ;  yep, that's the error i'm getting, it's coming up in a new window and giving me that error i posted in i think my second post here.  but i'm using strictly C++ not managed or anything   ;Quote:Original post by EvilKnuckles666uhoh... how'd that happened?  when i viewed the "this" pointer, i looked at the value of the map<> template and it said it has an <undefined value>... how would that happen?The instance of the object upon which you are calling the Add() member function is somehow not valid (bad pointer, scribbled upon by some out-of-bounds array access, etc.). Undefined value suggests that the map value hasn't been initialized; but there's no way that could happen assuming you got passed the object constructor; this in turn suggests that you're calling Add() upon a pointer-to-object where the pointer doesn't actually point at a valid object.   