so i ned to access a private variable from another class but i can figure out how to. here is the code
Code:
class Playerlist
{
private:
int size;
Player* player; // array
public:
Playerlist();
~Playerlist();
Playerlist (const Playerlist& playerlist);
int getSize() {return size;}
Player* getPlayer(int index) {return &player[index];}
};
Playerlist::Playerlist()
{
player = NULL;
cout << "How many players will be playing? " << endl;
cout << "* Number of players should not exceed the cubic dimensions * " << endl;
cin >> size;
player = new Player [size];
}
Playerlist::~Playerlist()
{
delete [] player;
}
Playerlist::Playerlist (const Playerlist& playerlist)
{
size = playerlist.size;
player = new Player [size];
for(int s = 0; s < size; s++)
player[s] = playerlist.player[s];
}
and this is how i thought you were suppose to do it
Code:
int size = size.getSize();
this is the class im trying to get it into
Code:
template <class TYPE>
bool Grid<TYPE>::winHorizontal(Player* player) //rows
{
int count;
for(int d = 0; d <DEPTH; d++){
for(int r = 0; r<ROW; r++){
for(int c = 0; c< COL; c++)
{
if(*player == *array[d][r][c].getPlayer())
count++;
}
if(count == COL)
return true;
count = 0;
}
}
return false;
}
template <class TYPE>
bool Grid<TYPE>::winVertical(Player* player) //columns
{
int count;
for(int c = 0; c <COL; c++){
for(int r = 0; r<ROW; r++){
for(int d = 0; d < DEPTH; d++)
{
if(*player == *array[d][r][c].getPlayer())
count++;
}
if(count == ROW)
return true;
count = 0;
}
}
return false;
}
template <class TYPE>
bool Grid<TYPE>::winDiagonal(Player* player) //diagonals
{
int count;
int size = size.getSize();
for(int i = 0; i < size; i++)
{
//cubic diagonal top front left to bottom back right
if(*player == *array [i][i][i].getPlayer())
count++;
//cubic diagonal bottom front left to top back right
else if(*player == *array[i][(size-1)-i][i].getPlayer())
count++;
//cubic diagonal top front right to bottom back left
else if(*player == *array[i][i][(size-1)-i].getPlayer())
count++;
//cubic diagonal bottom front right to top back left
else if(*player == *array[i][(size-1)-i][(size-1)-i].getPlayer())
count++;
}
for(int d = 0; d < DEPTH; d++){
for(int i = 0; i < size; i++)
{
// '\' diagonal check
if(*player == *array[d][i][i].getPlayer())
count++;
// '/' diagonal check
else if(*player == *array[d][i][(size-1)-i].getPlayer())
count++;
}
}
if(count == size)
return true;
count = 0;
return false;
}
template <class TYPE>
bool Grid<TYPE>::winCubic(Player* player) //depth
{
int count;
for(int r = 0; r < ROW; r++){
for(int c = 0; c < COL; c++){
for(int d = 0; d < DEPTH; d++)
{
if(*player == *array[d][r][c].getPlayer())
count++;
}
if(count == DEPTH)
return true;
count = 0;
}
}
return false;
}
without that size my code wont work how can i get the size from playerlist to that grid class function??