< Previous | Contents | Next >
The function askNumber() has two parameters—high and low. You can tell this from the function prototype:
int askNumber(int high, int low = 1);
Notice that the second parameter, low, looks like it’s assigned a value. In a way, it is. The 1 is a default argument meaning that if a value isn’t passed to low when the function is called, low is assigned 1. You specify default arguments by using = followed by a value after a parameter name.
Once you specify a default argument in a list of parameters, you must specify default arguments for all remaining parameters. So the following prototype is valid:
void setDisplay(int height, int width, int depth = 32, bool fullScreen = true);
while this one is illegal:
void setDisplay(int width, int height, int depth = 32, bool fullScreen);
By the way, you don’t repeat the default argument in the function definition, as you can see in the function definition of askNumber().
int askNumber(int high, int low)