Re: NULL
On Jun 23, 1:19 pm, "Jim Langston" <tazmas...@rocketmail.com> wrote:
Returning a pointer (as others have commented on) is a valid method. The
method I use for this, however, is to throw, since I want to return a
reference.
CPlayer& FindPlayer( const std::string Name )
{
for ( map_player::iterator i = World.ConnectedPlayers.begin(); i !=
World.ConnectedPlayers.end(); ++i)
{
if ( (*i).second.Character.Name == Name )
return (*i).second;
}
throw 0;
}
//////////////////
try
{
CPlayer& TargetPlayer = FindPlayer( Name );
PlayerMoveTo( TargetPlayer, ThisPlayer.Character.Map,
ThisPlayer.Character.Pos );
SendMessageToPlayer( Socket, MSG_SERVER_MESSAGE, Name + "
summoned." );
}
catch ( int )
{
SendMessageToPlayer( Socket, MSG_SERVER_MESSAGE, Name + " not
found." );
}
next time, don't be so cheap and use an exception class instead of an
ordinary int (which does not hold any error info)
Diego