int foo(int){
...
}
Any ideas?
Note the difference between parameters and arguments: Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function. Parameters are initialized to the values of the arguments supplied.
Parameters allow a function to perform tasks without knowing the specific input values ahead of time. Parameters are indispensable components of functions, which programmers use to divide their code into logical blocks.
An argument is a way for you to provide more information to a function. The function can then use that information as it runs, like a variable. Said differently, when you create a function, you can pass in data in the form of an argument, also called a parameter.
When you are not actually using the parameter in the function but do not want to break the public method signature.
One case where you define a function but do not name the parameter is given in Scott Meyers's "Effective C++, 3rd edition", Item 47:
template<typename IterT, typename DistT>
void doAdvance(IterT& iter, DistT d,
std::random_access_iterator_tag)
{
iter += d;
}
is used in:
template<typename IterT, typename DistT>
void advance(IterT& iter, DistT d)
{
doAdvance( iter, d,
typename std::iterator_traits<IterT>::iterator_category() );
}
Essentially, the third parameter in doAdvance is a type unaccompanied by a variable name, i.e. it is an unnamed parameter. Having an unnamed parameter isn't a problem, since that argument is only used during the resolution of which overloaded function to use. I discuss these topics in this related SO question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With