multiple errors, but the code is same as books

Mine is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//Game Lobby
//Simulates a game lobby where players wait

#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_pName; // Pointer to next player in list
};

Player::Player(const string& name) // constructor
	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;
};

Lobby::Lobby();
m_pHead(0)
{}

Lobby::~Lobby()
{
	Clear();
}

void Lobby()
{
	// creates a new player node
	cout << "Please enter the name of your 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() !=);
		{
			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 whos in the game lobby:\n"
			if (pIter == 0)
			{
				os << "The game 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 << "\nGAME LOBBY\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-bye.\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);
	return 0;
	}


Books is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//Game Lobby
//Simulates a game lobby where players wait

#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;  //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<<(ostream& os, const Lobby& aLobby);
    
public:
    Lobby();
    ~Lobby();
    void AddPlayer();
    void RemovePlayer();
    void Clear();
    
private:
    Player* m_pHead;  
};

Lobby::Lobby():
    m_pHead(0)
{}

Lobby::~Lobby()
{
    Clear();
}

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 << "\nGAME LOBBY\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-bye.\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);
    
    return 0;
}


But I still get this

1
2
3
4
5
6
7
1
1>  Source.cpp
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(22): error C3646: 'm_Name' : unknown override specifier
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(22): error C2065: 'name' : undeclared identifier
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(22): error C2761: '{ctor}' : member function redeclaration not allowed
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(24): error C2448: 'm_pNext' : function-style initializer appears to be a function definition
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(24): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You missed a colon between lines 21 and 22:

1
2
3
4
Player::Player(const string& name) :  //<- you need a colon here
	m_Name(name), 
	m_pNext(0)
{}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//Game Lobby
//Simulates a game lobby where players wait

#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; // Pointer to next player in list
};

Player::Player(const string& name): // constructor
	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;
};

Lobby::Lobby();
m_pHead(0)
{}

Lobby::~Lobby()
{
	Clear();
}

void Lobby::AddPlayer()
{
	// creates a new player node
	cout << "Please enter the name of your 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() != )
		{
			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 whos in the game lobby:\n";
			if (pIter == 0)
			{
				os << "The game 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 << "\nGAME LOBBY\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-bye.\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);

	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
1>  Source.cpp
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(53): error C2761: '{ctor}' : member function redeclaration not allowed
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(55): error C2448: 'm_pHead' : function-style initializer appears to be a function definition
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(79): error C2059: syntax error : ')'
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(80): error C2143: syntax error : missing ';' before '{'
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(111): error C2061: syntax error : identifier 'os'
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(112): error C2805: binary 'operator <<' has too few parameters
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(113): error C2065: 'aLobby' : undeclared identifier
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(113): error C2228: left of '.m_pHead' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(114): error C2065: 'os' : undeclared identifier
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(117): error C2065: 'os' : undeclared identifier
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(124): error C2065: 'os' : undeclared identifier
1>c:\users\admin\documents\visual studio 2012\projects\game lobby program\game lobby program\source.cpp(129): error C2065: 'os' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
A couple of other differences.

1
2
3
Lobby::Lobby():<--
    m_pHead(0)
{}


1
2
3
Lobby::Lobby();//<--
m_pHead(0)
{}



1
2
3
4
5
6
7
8
9
10
//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);
    }


1
2
3
4
5
6
7
8
9
10
	// otherwise find the end of the list and add the player there
	else
	{
		Player* pIter = m_pHead;
		while(pIter->GetNext() != )//<--
		{
			pIter = pIter->GetNext();
		}
		pIter->SetNext(pNewPlayer);
	}
and here
ostream& operator<<(ostream& os, const Lobby& aLobby)

ostream& operator<<(ostream&, os, const Lobby& aLobby)
EDIT: I kept putting commas in the wrong places i.e ostream&, os which caused a ton of errors. Cheers mate :)
Last edited on
Topic archived. No new replies allowed.