< Previous | Contents | Next >
1. Improve the Lobby class from the Game Lobby program by writing a friend function of the Player class that allows a Player object to be sent to cout. Next, update the function that allows a Lobby object to be sent to cout so that it uses your new function for sending a Player object to cout.
2. The Lobby::AddPlayer() member function from the Game Lobby pro- gram is inefficient because it iterates through all of the player nodes to add a new player to the end of the line. Add an m_pTail pointer data member to the Lobby class that always points to the last player node in the line and use it to more efficiently add a player.
Exercises 329
3. What’s wrong with the following code?
#include <iostream> using namespace std;
int main()
{
int* pScore = new int;
*pScore = 500;
pScore = new int(1000); delete pScore;
pScore = 0;
return 0;
}
This page intentionally left blank