W
werasm
Phlip said:5) return an iterator, and check if that == .end().
CMap & found = FindMap(2);
Now found refers to the temporary NullMap(), which destructed somewhere
around ;.
Should not work - cannot bind an rvalue (temporary) to a non-constant
reference. I know it compiles under MS VC++ 7.1, but that is erroneous.
This leaves you with this option (or an exception):
....
{
std::map<unsigned int, CMap*>::iterator ThisMapIt =
World.Maps.find( ThisPlayer.Character.Map );
if ( ThisMapIt != World.Maps.end() )
{
return *((*ThisMapIt).second);
}
else
{
//Same base type as CMap, but you know that!
static NullMap sentinal;
return sentinal;
}
}