Question: 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

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 count so that it uses your new function for sending a Player object to cout.

This is what I have so far and there is an error that I am not sure why I am getting though I checked the code several times to see why its giving me the errors.

Improve the Lobby class from the Game Lobby program by writing a

This is the code below:

//Game Lobby

//Simulates a game lobby where players wait

#include

#include

using namespace std;

class Player

{

public:

Player(const string&name = "");

string GetName()const;

Player*GetNext()const;

void SetNext(Player*next);

private:

string m_Name;

Player*m_pNext; //Pointer to next player in list

};

Player::Player(const string&name) :

m_Name(name),

m_pNext(0)

{}

string Player::GetName()const

{

return m_Name;

}

Player*Player::GetNext()const

{

return m_pNext;

}

void Player::SetNext(Player*next)

{

m_pNext = next;

}

class Lobby

{

friend ostream&operator

public:

Lobby();

~Lobby();

void AddPlayer();

void RemovePlayer();

void Clear();

private:

Player*m_pHead;

};

void Lobby::AddPlayer()

{

//create a new player node

cout

string name;

cin >> name;

Player*pNewPlayer = new Player(name);

//if list is empty, make head of list this new player

if (m_pHead == 0)

{

m_pHead = pNewPlayer;

}

//otherwise find the end of the list and add the player there

else

{

Player*pIter = m_pHead;

while (pIter->GetNext() != 0)

{

pIter = pIter->GetNext();

}

pIter->SetNext(pNewPlayer);

}

}

void Lobby::RemovePlayer()

{

if (m_pHead == 0)

{

cout

}

else

{

Player*pTemp = m_pHead;

m_pHead = m_pHead->GetNext();

delete pTemp;

}

}

void Lobby::Clear()

{

while (m_pHead != 0)

{

RemovePlayer();

}

}

ostream&operator

{

Player*pIter = aLobby.m_pHead;

os

if (pIter == 0)

{

os

}

else

{

while (pIter != 0)

{

os GetName()

pIter = pIter->GetNext();

}

}

return os;

}

int main()

{

Lobby myLobby;

int choice;

do

{

cout

cout

cout

cout

cout

cout

cout

cin >> choice;

switch (choice)

{

case 0: cout

case 1: myLobby.AddPlayer(); break;

case 2: myLobby.RemovePlayer(); break;

case 3: myLobby.Clear(); break;

default:cout

}

}

while (choice != 0);

return 0;

}

Error List * 3 Errors ! ! 0Warnings | 00 Messages Search Error List File lobby.obj lobby.obj lobby.exe Line Column Project Description error LNK2019: unresolved external symbol "public:_thiscall Lobby:Lobby(void)" (220Lobby@@OAE@XZ) referenced in function_main 2 error LNK2019: unresolved external symbol "public:_thiscall Lobby: Lobby(void)" (?21Lobby@@OAE@XZ) referenced in function_main 3 error LNK1120: 2 unresolved externals lobby lobby lobby

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!