Remove unused argument names in the function definition (coding standards).

Herb Suttter C ++ encoding standards say: “It’s good practice to remove unused argument names in functions to write a null warning program.

Example:

int increment(int number, int power=0){
   return number++;
}

it should be

int increment(int number, int /*power*/=0){
   return number++;
}

If there is an argument "unused variables" for the argument power. This works great for programs (no compilation errors), so new function definitions will

int increment(int number, int =0)

So what does the int=0compiler mean ?

+5
source share
2 answers

A formatless formal parameter with a default value of 0.

The first case (the most popular) is using in function-declaration, something like

int increment(int, int = 0);

.

int increment(int number, int power)
{
   //
}

- , , .

+4

, , ,

int increment(int number/*, int power=0*/);

:

  • , ,
  • ,

, unnamed- , , - cpp .

// Forward declaration
int increment(int number, int =0);

// Somewhere in cpp file:
int increment(int number, int power)
  {
  return pow(number, power);
  }
+2

All Articles