Game Lobby Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fishirboy
    New Member
    • Mar 2013
    • 48

    Game Lobby Program

    I am having a debug error i can't find saying:

    Error 2 error LNK2019: unresolved external symbol "public: __thiscall Lobby::Lobby(vo id)" (??0Lobby@@QAE@ XZ) referenced in function _main

    and

    Error 1 error LNK2019: unresolved external symbol "public: __thiscall Lobby::~Lobby(v oid)" (??1Lobby@@QAE@ XZ) referenced in function _main

    and

    Error 3 error LNK1120: 2 unresolved externals




    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    
    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;
    };
    
    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 << (ostream& os, const Lobby& aLobby);
    
    public:
    	Lobby();
    	~Lobby();
    	void AddPlayer();
    	void RemovePlayer();
    	void Clear();
    
    private:
    	Player* m_pHead;
    };
    
    void Lobby::AddPlayer()
    {
    	//create a new player node
    	cout << "Please enter the name of the new player: ";
    	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 << "The game lobby is empty. No one to remove!\n";
    	}
    	else
    	{
    		Player* pTemp = m_pHead;
    		m_pHead = m_pHead->GetNext();
    		delete pTemp;
    	}
    }
    
    void Lobby::Clear()
    {
    	while (m_pHead != 0)
    	{
    		RemovePlayer();
    	}
    }
    
    ostream& operator<<(ostream& os, const Lobby& aLobby)
    {
    	Player* pIter = aLobby.m_pHead;
    	os << "\nHere's who's in the game lobby:\n";
    	if (pIter == 0)
    	{
    		os << "The lobby is empty.\n";
    	}
    	else
    	{
    		while (pIter != 0)
    		{
    			os << pIter->GetName() << endl;
    			pIter = pIter->GetNext();
    		}
    	}
    
    	return os;
    }
    
    int main()
    {
    	Lobby myLobby;
    	int choice;
    
    	do
    	{
    		cout << myLobby;
    		cout << "\nGAMELOBBY\n";
    		cout << "0 - Exit the program.\n";
    		cout << "1 - Add a player to the lobby.\n";
    		cout << "2 - Remove a player from the lobby\n";
    		cout << "3 - Clear the lobby.\n";
    		cout << endl << "Enter choice: ";
    		cin >> choice;
    
    		switch (choice)
    		{
    		case 0: cout << "Good-buy.\n"; break;
    		case 1: myLobby.AddPlayer(); break;
    		case 2: myLobby.RemovePlayer(); break;
    		case 3: myLobby.Clear(); break;
    		default: cout << "That was not a valid choice.\n";
    		}
    	}
    	while (choice != 0);
    
    	system("pause");
    	return 0;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There's no code for Lobby::Lobby().

    Be sure your member functions are coded in a .cpp fie and only the class declaration should be in the header file.

    Comment

    Working...