The default parameter refers to the automatic use of a default value when an argument is omitted from a function call.
For a function with a parameter list, you must add a default value from right to left (that is, her right side must have a default value first)
Fun (int, int,1,int,int), etc. It's clear enough!!
1 Char* Left (Const Char* STR,intn=1);2 intMain ()3 {4 }5 6 Char* Left (Const Char* STR,intn =1)//Error7 {8}
1 declaration with default parameters, no default value when implemented (OK)
2 implemented with default parameters, no default value declared (OK)
1 Char* Left (Const Char* STR,intn=1);2 intMain ()3 {4 }5 6 Char* Left (Const Char* STR,intN)7 {8 9}
1 Char* Left (Const Char* STR,intn);2 intMain ()3 {4 5 }6 Char* Left (Const Char* STR,intn =1)7 {8 9}
Use default parameters to override function overloading:
If a set of overloaded functions (which may have default parameters) allows the same number of calls , the two semantics of the call will be raised.
1 voidFuncint);//one of the overloaded functions2 voidFuncint,int=4);//two of the overloaded functions with default parameters3 voidFuncint=3,int=4);//three of the overloaded functions with default parameters4 5Func7);//error: Which of the 3 overloaded functions is called?6Func -, -)//error: Which one of the following 2 overloaded functions is called?
Careful,!!!!!!!!!!!!!.
Default parameter learning for functions in C + +