Default arguments are possible. The problem here is that a bool
cannot have a null
value. So there are a few possibilities for you. You can either give that argument a default value that is a valid bool
:
void GatherMovements(bool xPositions, bool yPositions, bool zPositions = false);
Or you can have two overloads of the function - one that takes 3 arguments and one that takes 2:
void GatherMovements(bool xPositions, bool yPositions, bool zPositions);
void GatherMovements(bool xPositions, bool yPositions);
One function may call the other if they can be implemented in terms of each other.
The second approach is only necessary if calling the function with true
, false
, and no final parameter are fundamentally different operations.
If you really want only one function and the three cases should be considered different, then one final option for you is to use a boost::optional
:
void GatherMovements(bool xPositions, bool yPositions, boost::optional<bool> zPositions);
However, I suggest that the overload approach is preferable (no dealing with extra unnecessary types).