Herb Suttter C++ coding standards says, It is good practice to delete unused argument names in functions to write zero warning program.
Example:
int increment(int number, int power=0){
return number++;
}
should be
int increment(int number, int /*power*/=0){
return number++;
}
If there is 'unused variable warning' to power
argument.
This works fine for programs (no compile errors), So new function definitions will be
int increment(int number, int =0)
So what does int=0
mean to compiler?
Unnamed formal parameter with a default value equal to 0.
First case (most popular) is an usage in function-declaration
, something like
int increment(int, int = 0);
and in definition parameter will be named.
int increment(int number, int power)
{
//
}
Second case is an usage for debug purposes, or for some features, that are not implemented yet, or for dummy functions.
If this is a standalone function, of course, you can change method's signature commenting out last parameter
int increment(int number/*, int power=0*/);
but, you may want to keep method's signature unchanged in case:
Also, default value for unnamed parameter can be useful when you use it in function declaration and later somewhere in cpp file you still give name to that variable.
// Forward declaration
int increment(int number, int =0);
// Somewhere in cpp file:
int increment(int number, int power)
{
return pow(number, power);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With