So I was making a programm with a class bingocard and a class player. Each player can have a maxium number od bingocards which you give it in the constructor of the player class. In the constructor we also have a dynamic array where we save each bingocard which is a 4x4 matrix (2d array).
class Bingocard
{
private:
unsigned int card[4][4];
public:
Bingocard();
Bingocard(unsigned int Card[4][4]);
Bingocard(const Bingocard& Card);
Bingocard operator=(const Bingocard& Card);
};
BingocardBingocard()
{
}
Bingocard::Bingocard(unsigned int Card[4][4])
{
for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
card[i][j] = Card[i][j];
}
Bingocard::Bingocard(const Bingocard& Card)
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
card[i][j] = Card.card[i][j];
}
Bingocard Bingocard::operator=(const Bingocard& Card)
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
this->card[i][j] = Card.card[i][j];
return (*this);
}
class Player
{
private:
unsigned int maxNumberCards;
Bingocard* cards;
unsigned int numberCards;
public:
Player(unsigned int k);
void newCard(Bingocard* Card);
~Player();
};
Player::Player(unsigned int k)
{
numberCards = 0;
maxNumberCards = k;
cards = new Bingocard[maxNumberCards];
}
void Player::newCard(Bingocard* card)
{
if (numberCards < maxNumberCards) {
cards[anzahlKarten] = *card; //Assign operator is triggered;
anzahlKarten += 1;
}
else
cout << "Maximum cards reached! Adding more cards is not possible now." << endl;
}
Player::~Player()
{
delete[] cards;
}
I have now that dynamic array called cards in the class Player and I want to access each of its elements but I dont know which command to use. I know I can make a function for example getElement and give it the row and column I want as parameters, but I was wondering if I can do that the same thing without a function. I tried (cards[a])[b][c] but it gives an error back. I need this to work so I can check each number on the card for a bingo.