vexing with vectors!

hi there,
been on this for hours now and i just can't seem to populate my vector with pointers to another class object. can anyone see where i am going wrong please. thankyou in advance.

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
// 
#include<iostream>
#include<vector>
using namespace std;

 unsigned  int PLAYERS = 0;
 unsigned  int ROUNDS = 0;
static char *NAMES[] = {
      "Dog", "Car", "Hat", "Iron", "Ship", "Thimble" 
   };
class CGamePlay
{
private:
	unsigned int mPlayers;
	unsigned int mGames;
	
public:
	//CPlayer *thisPlayer;//("Dog", 0, 0, 0);
	CGamePlay();
	int GetPLayers();
	int GetGames();
	void SetGame(int player, int round); //: mPlayerNum(player), mGames(round){};
	int Play();
	//int CreatePlayers();
	
	~CGamePlay();
};

void CGamePlay::SetGame(int player, int round)
{
	mPlayers = player;
	mGames = round;
	}
int CGamePlay::GetPLayers()
{
return mPlayers;
}

int CGamePlay::GetGames()
{
return mGames;
}

CGamePlay::~CGamePlay(void) 
{
	
}


int CGamePlay::Play()
{ 
	CPlayer* thisPlayer = new CPlayer("Dog", 0, 0, 0);
	CTeamList thisTeam( mPlayers);
	thisTeam.AddPlayer( *thisPlayer);
	//GetBoard();
	for (unsigned int i = 0; i < ROUNDS; i++ )
	{		
		CPlayer* thatPlayer = thisPlayer;
		thisTeam.AddPlayer(*thatPlayer);
		//NextPlayer();
		//RollDice();
		//Banker();
	}
	return 0;
}
class CPlayer :
	public CGamePlay
{
private:
	char* mpName;
	unsigned int mPlayerNum;
	int	mWealth;
	unsigned int mPosition;
public:
	//CPlayer( );
	CPlayer(char* mpName, unsigned int mPlayerNum, int mWealth, unsigned int mPosition);
	CPlayer( CPlayer &CPcopy );
	CPlayer& operator= ( CPlayer &CPcopy);
	friend class  CGamePlay;
//	CPlayer *thisPlayer;//("Dog", 0, 0, 0);
	~CPlayer(void);
};
CPlayer::CPlayer(char* mpName, unsigned int mPlayerNum, int mWealth, unsigned int mPosition)
{
	mpName = NAMES[mPlayerNum];
	mPlayerNum = 0;
	mWealth = 0;
	mPosition = 0;
}
CPlayer::CPlayer( CPlayer &CPcopy )
		{
			mPlayerNum++;
	 NAMES[mPlayerNum] = CPcopy.mpName;
	mPlayerNum = CPcopy.mPlayerNum;
	mWealth = CPcopy.mWealth;
	mPosition = CPcopy.mPosition;
}
CPlayer& CPlayer::operator= (CPlayer &CPcopy)
{
if (this == &CPcopy) return *this;
		mPlayerNum++;
	 NAMES[mPlayerNum] = CPcopy.mpName;
	mPlayerNum = CPcopy.mPlayerNum;
	mWealth = CPcopy.mWealth;
	mPosition = CPcopy.mPosition;
	return *this;
}
CPlayer::~CPlayer(void)
{
}
class CTeamList :
	public CPlayer
{
private:
	std::vector<CPlayer*> mTeam;
public:
	CTeamList( unsigned int players);
	void AddPlayer(CPlayer &thisPlayer);
	~CTeamList(void);
};

CTeamList::CTeamList(unsigned int players)
{
	vector<CPlayer*> mTeam(players);
	
}
void CTeamList::AddPlayer(CPlayer &thisPlayer)
{
	mTeam.push_back(&thisPlayer);

	//CTeamList::mTeam[thisPlayer.mPlayerNum].push_back(thisPlayer); Thanks toum!
}

CTeamList::~CTeamList(void)
{
}
int main()
{
	CGamePlay thisGame ;
	cout << "Enter number of players: \n";
	cin >> PLAYERS;
	cout << "Enter number of rounds: \n";
	cin >> ROUNDS;
	thisGame.SetGame(PLAYERS, ROUNDS);
	thisGame.Play();
	system ("pause");
	return 0;
}

well here I am back again a few hours later and still no joy!
I am trying to create an object then put a pointer to it in the 1st vector element. After this i try to invoke the overridden operator to copy this object and push back as many objects as the user chooses PLAYERS. Any further guidance will be incredibly well received!!
Last edited on
mTeam.push_back(&thisPlayer);
Topic archived. No new replies allowed.