A default parameter
in C ++, is the default parameters specify a default value for the parameter of the function declaration or the function is defined. When the function is called, if no argument is used the default value, otherwise specified arguments.
Full default parameters
void TestFunc(int a = 10, int b = 20, int c = 30) {
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
cout<<"c = "<<c<<endl; }
Semi default parameters
void TestFunc(int a, int b = 10, int c = 20) {
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
cout<<"c = "<<c<<endl; }
Second, the parameters of the default rule
- Semi default parameters must be given in sequence from right to left, not to the interval
- The default parameters can not both be in function declarations and definitions (can only be defined in a statement, but also in the definition, only choose one)
- The default value must be a constant or a global variable