Reputation: 39354
I understand that function prototypes don't need to have a name associated with the parameters. For example:
void foo(int, std::string);
I was interested to find out recently that you could do the same thing in a function definition though:
void* foo(void*) { std::cerr << "Hello World!" << std::endl; }
Why does this work and how could you ever make use of an un-named parameter? Is there a reason this is allowed (like maybe dealing with legacy interfaces or something along those lines)?
Upvotes: 4
Views: 86
Reputation: 272802
If you don't intend to use the argument, then this is a good way of preventing compilers from warning you about it.
This does indeed come up most often in the context of satisfying interfaces. For instance. you may be overriding a base-class method, but have no use for the parameters.
Upvotes: 7