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?
But this does work: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 }
IdeswaCode:player persons[3] = { player(country, difficulty, name), player(country2, difficulty, name2), player(country3, difficulty3, name3) };



LinkBack URL
About LinkBacks
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?



I used to be an adventurer like you... then I took an arrow to the knee.