An unnamed parameter in a function definition

I understand that function prototypes do not need to have a name associated with the parameters. For instance:

void foo(int, std::string); 

I was interested to know recently that you can do the same in a function definition, though:

 void* foo(void*) { std::cerr << "Hello World!" << std::endl; } 

Why does this work and how could you use an unnamed parameter? Is there a reason this is allowed (for example, maybe dealing with legacy interfaces or something like that)?

+4
source share
1 answer

If you are not going to use an argument, this is a good way to prevent compilers from you about it.

This really happens most often in the context of satisfying interfaces. For instance. you can override the base class method, but not use the parameters.

+7
source

Source: https://habr.com/ru/post/1385182/


All Articles