Im trying to make a very simple text game and I get really irritating error.
This line is causing me these problems -> Fleet fleet{1};
Initially I tried to write it like this -> Fleet fleet(1);
But I got this error: 'expected identifier before numeric constant'
. And after some googling I found the solution ()->{}
and compilator didn't display any error. After running the application I found out that it isnt working. After removing this line, everything runs how it should be.
Also I was trying writing it like that: Fleet() : fleet(1) {}
and then I get this error: expected unqualified-id before ')'
.
I'm using C::B if thats helpful at all.
class Ship{
public:
int max_HP;
int HP;
int DMG;
};
class Fleet{
public:
int amount_of_ships;
Ship * ship = new Ship[amount_of_ships];
Fleet(int fleet_size)
{
amount_of_ships=fleet_size;
}
};
class Player{
public:
string name;
Fleet fleet{1}; //this line
};
I really dont know why it does not work. Even if I create new Fleet object in main and write the same exact line, everything works how it should be. Also I should have mentioned it earlier - I'm doing absolutely NOTHING with Player class, and with Player's fleet at the moment. Any ideas on how to fix this? :/