I created a constructor that seems to work, but I think it might more complicated than needed.
Here's the Lobby class:
class Lobby
{
friend ostream& operator<<(ostream& os, const Lobby& aLobby);
public:
Lobby(): m_pHead(0) {}
~Lobby() {Clear();}
Lobby(const Lobby& l);
void AddPlayer();
void RemovePlayer();
void Clear();
private:
Player* m_pHead; //First Player on list
};
Here's the Player class:
class Player
{
public:
Player(const string& name = ""): m_Name(name), m_pNext(0) {}
string GetName() const {return m_Name;}
Player* GetNext() const {return m_pNext;}
void SetNext(Player* next) {m_pNext = next;}
private:
string m_Name;
Player* m_pNext;
};
and here's the copy constructor:
Lobby::Lobby(const Lobby& l)
{
if (l.m_pHead != 0)
{
m_pHead = new Player;
*m_pHead = *l.m_pHead;
Player* pIter = m_pHead->GetNext();
Player* pHeap;
while (pIter != 0)
{
pHeap = new Player;
*pHeap = *pIter;
pIter = pIter->GetNext();
}
}
else
{
m_pHead = 0;
}
}
Thanks, any help/explanations would be appreciated.