Hello.How can it be that some functions have parameters withh no name specified in the definition(just the type is modified).I had not encounter it in my life till tomorrow
They're either unused, or the name is omitted in the prototype as a shortcut.
1 2 3 4 5 6 7 8 9 10 11
void example(int)
{
// perfectly legal, but the passed parameter can't be used
}
void another(int); // legal prototype
void another(int foo) // but for the definition you can give it a name
{
// now the param can be used, even though it's nameless in the prototype.
}
Note that if you give a parameter a name, then fail to use the parameter within the function, a good
compiler will generate a warning. If the function does not use the parameter, then the best practice
is to leave it unnamed.
(This happens mostly when dealing with inheritance and virtual functions).
No doubt. Besides it is stray one, so to speak. It has only an offset from
the beginning text line unlike its prototype having nothing but a symbols string.
There are also classified ones, they said to be methods that are incompatible with
stray ones. In addition there are standard conversions acting on behind.
Neverthless explicite ones that should be handled with extreme care.
Better never.
As long as there is one named parameter, you can have as many nameless ones as you want and still be able to access them. You can do it the same way as you would with Variable Argument Lists. ;)
The most common reason I can think of is that the function is a callback and the interface requires that it takes certain parameters, but the function's behavior doesn't need all of them, so you just leave the ones you don't need unnamed.