This is a very basic question, so please bear with me.
Consider the following function in C++:
void foo(int a, int b, int c)
{
//do something
}
can I call this function like this: foo(b=2, c=3, a=2)
?
I suppose this have some sort of name (positional parameters, possibly). If you could clarify it in the answer too, it would great.
A positional parameter is a parameter denoted by one or more digits, other than the single digit 0 . Positional parameters are assigned from the shell's arguments when it is invoked, and may be reassigned using the set builtin command.
A typical example of a shell that uses positional parameters is bash. You can use bash on Linux, BSD, macOS X, and Windows 10. Consider the following bash command. The command name is mycommand.
A positional parameter is a variable within a shell program; its value is set from an argument specified on the command line that invokes the program. Positional parameters are numbered and are referred to with a preceding ``$'': $1, $2, $3, and so on. A shell program may reference up to nine positional parameters.
A positional parameter is set by its index in the clause. A named parameter is set by its name. When you are setting the values, you might have the values in an array, in which case the positional form could me more useful.
Not in standard C++, no. You'll have to provide the parameters in the order specified by the function prototype.
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