The declaration does not have any programmatic advantages or disadvantages. However, there is one advantage of the style that I can think of:
If you are not using a parameter in a function, you cannot name this parameter in a declaration AND definition:
void foo(int); void foo(int) { }
Naming parameters that you do not use in the definition are not illegal, but this is a warning! The approval of the style that I mentioned will not point to the parameters in the declaration, so anyone who views the header file will know that a particular parameter is not used in the definition. However, this is only if you synchronize the unnamed name between the definition and the declaration.
Here is an example of when you can omit the parameter:
class Base { virtual void foo(int a) = 0; }; class Child1 { virtual void foo(int a) { std::cout << a + 1 << std::endl; } }; class Child2 { virtual void foo(int) { std::cout << "mwahaha" << std::endl; } };
In this case, the parameter is not named, but it must still be specified, since the prototype of the function must match the name of its parent.
source share