I am trying to create a player object that has its own array of Territories but whenever I compile these errors appear :
Player.cpp(15,4): error C2065: 'playerTerritories': undeclared identifier
Player.cpp(27,11): error C2065: 'playerTerritories': undeclared identifier
Player.h(15,29): error C3646: 'playerTerritories': unknown override specifier
Player.h(15,29): error C2143: syntax error: missing ',' before '['
Player.h(15,32): error C2143: syntax error: missing ')' before ';'
Player.h(15,32): error C2238: unexpected token(s) preceding ';'
I have tried moving the array to the cpp file but then the array becomes undefined in the toDefend method.
This is how my cpp file looks so far:
#include "Player.h"
#include <iostream>
using std::cout;
//Arrays for territories to choose from
extern std::string territoriesArr[] = { "Alaska","North West Territories", "Quebec", "Alberta", "Ontario", "Eastern US", "Western US", "Mexico", "Venezuela", "Peru", "Brazil", "Argentina" };
//The territories of our enemy
extern std::string enemy_territoriesArr[] = { "Great Britain", "Iceland", "Northern Europe", "Western Europe", "Southern Europe", "Scandanavia" };
//The array of cards that we can draw
extern std::string cardTypeArr[] = { "bomb", "reinforcement", "blockade", "airlift", "diplomacy" };
Player::Player() {
//Randomly choose territories and place into our playerTerritories array, we dont care about dupilcates for now
for (int i = 0; i < 6; i++) {
int r = rand() % 12;
playerTerritories[i] = Territory(territoriesArr[r]);
}
//Randomly choose cards and place into our card array
for (int i = 0; i < 3; i++) {
int r = rand() % 5;
playerHand[i] = Card(cardTypeArr[r]);
}
}
//Method to print out all the territories of a player
void Player::toDefend() {
cout << "Territories to defend: ";
for (int i = 0; i < 6; i++) {
cout << playerTerritories[i].getTerritoryName() << std::endl;
}
}
//Method to print out all the enemy territories
void Player::toAttack() {
cout << "Territories to attack";
for (std::string x : enemy_territoriesArr) {
cout << x << std::endl;
}
}
void Player::getPlayerHand() {
cout << "Cards in hand";
for (Card x : playerHand) {
cout << x.getCardName() << std::endl;
}
}
and my h file looks like
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
class Player {
public:
Player();
void toDefend();
void toAttack();
//void issueOrder(std::string order); TODO latter
void getPlayerHand();
//void getOrderList(); TODO latter
private:
Territory playerTerritories[6];
Card playerHand[3];
};
class Territory {
public:
Territory();
Territory(std::string name);
std::string getTerritoryName();
private:
std::string territoryName;
};
class Card{
public:
Card();
Card(std::string type);
std::string getCardName();
private:
std::string cardType;
};
class Order {
public:
Order(std::string name);
private:
std::string orderName;
};
#endif
Help would be much appreciated
Territory playerTerritories[6];the typeTerritoryis not known yet. Although I would expect a different error message. Same goes forCard playerHand[3];