   Beginning C++ Game Programming
  I saw that there was a post about the Exercise in Chapter 9 for Beginning C++ through Game Programming. But I have the older edition of the book.I get stuck in the following question in the book:Improve the Lobby class from the Game Lobby program by writing a copy constructor and an overloaded assignment operator for it.I have read other references about the copy constructor and the way to overload assignment operator, but I still do not know how to implement it. the lobby is a linkied list of player object, so I feel confused when i think how to make copy constructor and overloaded assignment operator for it.Can anyone help? Thank you very much.#include &lt;iostream&gt;#include &lt;string&gt;using namespace std;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; //Pointer to next player in list};class Lobby{   friend ostream& operator&lt;&lt;(ostream& os, const Lobby& aLobby);   /*friend Lobby& operator=(const Lobby& aLobby);*/public:   Lobby(): m_pHead(0) {}   ~Lobby() { Clear(); }   void AddPlayer();   void RemovePlayer();   void Clear(); private:   Player* m_pHead;};void Lobby::AddPlayer(){   //create a new player node   cout &lt;&lt; "Please enter the name of the new player: ";   string name;   cin &gt;&gt; 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-&gt;GetNext() != 0) {    pIter = pIter-&gt;GetNext(); }    pIter-&gt;SetNext(pNewPlayer);   }}void Lobby::RemovePlayer(){   if (m_pHead == 0)   { cout &lt;&lt; "The game lobby is empty. No one to remove!\n";   }   else   { Player* pTemp = m_pHead; m_pHead = m_pHead-&gt;GetNext(); delete pTemp;   }}void Lobby::Clear(){while (m_pHead != 0)   {RemovePlayer();}}ostream& operator&lt;&lt;(ostream& os, const Lobby& aLobby){   Player* pIter = aLobby.m_pHead;   os &lt;&lt; "\nHere's who's in the game lobby:\n";   if (pIter == 0)   { os &lt;&lt; "The lobby is empty.\n";   }   else   { while (pIter != 0) {    os &lt;&lt; pIter-&gt;GetName()  &lt;&lt; endl;    pIter = pIter-&gt;GetNext(); }   }   return os;}int main(){   Lobby myLobby;   int choice;   do   { cout &lt;&lt; myLobby; cout &lt;&lt; "\nGAME LOBBY\n"; cout &lt;&lt; "0 - Exit the program.\n"; cout &lt;&lt; "1 - Add a player to the lobby.\n"; cout &lt;&lt; "2 - Remove a player from the lobby.\n"; cout &lt;&lt; "3 - Clear the lobby.\n"; cout &lt;&lt; endl &lt;&lt; "Enter choice: "; cin &gt;&gt; choice; switch (choice) {    case 0: cout &lt;&lt; "Good-bye.\n"; break;    case 1: myLobby.AddPlayer(); break;    case 2: myLobby.RemovePlayer(); break;    case 3: myLobby.Clear(); break;    default: cout &lt;&lt; "That was not a valid choice.\n"; }   }   while (choice != 0);   cout &lt;&lt; "Press Enter to exit" ;   cin.ignore(cin.rdbuf()-&gt;in_avail() + 1);   return 0;}[Edited by - edmondsnake on June 15, 2009 3:08:19 AM]
  Use [source][/source] for source code, not quote tags.   ;  Hello,A basic implementation of that would be( mostly in pseudocode)constructor:Lobby(Lobby & other){@foreach Player P in other.m_pHead@ make a copy of P in TMP@ add to your Player list this->m_pHead  the TMP Player with TMP->m_pNextpointing to a element in this->m_pHead list not other.m_pHead@end foreach}almost the same with the operator = :Lobby& operator = (Lobby & other){ @destroy your list this->m_pHead;same code from here onreturn (*this);}Raxvan   ;  My answer: Adding copy/assignment would not be an improvement to that class :pThe player structures seem to be owned by the lobby, so the copy lobby would have to make its own list of players, so the player class would need a copy constructor too. But having 2 copies of a player lobby floating around seems like a bad idea to begin with. Doesn't seem like a very good book if they're trying to teach you to write copy constructors for every class you create, even when you never plan to use them. Writing code that will never be used is dumb.   