Can I use default arguments in a constructor like this maybe
Soldier(int entyID, int hlth = 100, int exp = 10, string nme) : entityID(entyID = globalID++), hea
Default arguments can only be supplied to a continuous range of parameters that extends to the end of the parameter list. Simply speaking, you can supply default arguments to 1, 2, 3, ... N last parameters of a function. You cannot supply default arguments to parameters in the middle of the parameter list, as you are trying to do above. Either rearrange your parameters (put hlth
and exp
at the end) or supply a default argument for nme
as well.
Additionally, you constructor initializer list doesn't seem to make any sense. What was the point of passing entyID
and nme
from outside, if you override their values anyway in the constructor initializer list?