I am filling two players' hands with random dominoes and have no issue. When I send the struct to another class, I cannot access the players hands anymore.
using namespace std;
struct player {
int playerNum;
vector < pair <int, int>> hand;
};
vector < pair <int, int>> availablePieces;
void Player::createHand(vector < pair <int, int>> &multiVector, player* player) {
srand(time(NULL)); // rand seed
int ranNumb;
//fill players' hand
for (int i = 0; i < 10; i++) {
ranNumb = rand() % multiVector.size();
player[0].hand.push_back(multiVector[ranNumb]);
multiVector.erase(multiVector.begin() + ranNumb);
ranNumb = rand() % multiVector.size();
player[1].hand.push_back(multiVector[ranNumb]);
multiVector.erase(multiVector.begin() + ranNumb);
}
setAvailablePieces(multiVector);
Game gameObj;
gameObj.API(player, availablePieces);
Game Header:
using namespace std;
class Game
{
public:
void API(struct player* player, vector < pair <int, int>> &availablePieces);
private:
void playGame(player* player, vector < pair <int, int>>& availablePieces);
};
Game Class:
void Game::playGame(player* player, vector < pair <int, int>>& availablePieces) {
cout << player[0].hand[0].first << endl;
}
void Game::API(player* player, vector < pair <int, int>> &availablePieces) {
playGame(player, availablePieces);
}
In the function playGame, I cannot access the individual players hands. I get the error: Expression must be a pointer to a complete object type.
Aucun commentaire:
Enregistrer un commentaire