I need for my "console-text-based-generals-strategy-game" an array of objects. The size of the array depends on user input. I tried some ideas, but it keeps giving me errors. Should I overload new and delete?
Code:
// player class
class player
{
public:
// variables
int soldiers;
int tanks;
int planes;
int artil;
int barracks;
int warfactory;
int airfield;
int supctr;
int supcar;
// methods
player(string c, int diff, string n);
~player();
string getcountry();
void setgold(int g);
string getname();
int getgold();
string battle_start(player & p2);
private:
string * name;
string * country;
int * gold;
};
// in the newgame() function
player persons[players];
for(int i = 0; i < players; i++)
{
persons[players](country, difficulty, name); // use constructor
}
But this does work:
Code:
player persons[3] =
{
player(country, difficulty, name),
player(country2, difficulty, name2),
player(country3, difficulty3, name3)
};
Ideswa