If you're okay with the returned reference being const, you can do something like this:
const string & ReturnKey(int a)
{
static const string defaultValue; // to be returned if object isn't found
map<int,string>::iterator iter = mymap.find(a);
if(iter != mymap.end())
{
return iter->second;
}
else return defaultValue;
}
It's safe to return a reference to (defaultValue) in the not-found case because defaultValue is declared static and therefore will still exist after the function returns. In the value-found case, the caller will need to be careful not to hold the reference and try to use it after mymap has been cleared or modified, but that's usually not an issue in practice.