Parameter Names in Function Declarations

C++You can supply parameter names in a function declaration, but the compiler ignores them except in the following two situations:

  1. If two parameter names have the same name within a single declaration. This is an error.
  2. If a parameter name is the same as a name outside the function. In this case the name outside the function is hidden and cannot be used in the parameter declaration.

In the following example, the third parameter name intersects is meant to have enumeration type subway_line, but this name is hidden by the name of the first parameter. The declaration of the function subway() causes a compile-time error because subway_line is not a valid type name because the first parameter name subway_line hides the namespace scope enum type and cannot be used again in the second parameter.

enum subway_line {yonge,
university, spadina, bloor};
int subway(char * subway_line, int stations,
                  subway_line intersects);

Related References

IBM Copyright 2003