default argument

Can someone tell me what a default argument is in a function?

1
2
3
4
5
6
7
8
9
10
bool isLegal(int age, int minAge = 21)
{
 return age >= minAge;
}

legal = isLegal(age); // same as isLegal(age, 21)
if (inLouisiana())
{
 legal = isLegal(age, 18);
}


The call isLegal(age) is completely equivalent to isLegal(age, 21). C++ just
provides the default argument for you. The call to isLegal(age, 18) ignores the
default value.
Last edited on
So, a default argument is not set to a value in the declaration? I can't really tell, microsoft always explains things in a way that's hard to understand.
closed account (SECMoG1T)
This is legal int minAge = 21
Topic archived. No new replies allowed.