0
Any defaults should be on the right side of any non default arguments?? I cant understand this!
When using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected.
3 ответов
0
I think what they mean is:
First you should write some arguments, for example if(x=1), if those arguments aren't true, the default statement should be executed. If the default statement is at the beginning, it'll always get executed, because there are no true other statements before it
+ 1
Suppose you have a function
void fun (int x, int y=5)
{
// function body
}
when calling this function
fun(1) //works b/se it uses x=1 and the
default for y=5
fun(1,2) // works
but if you use the default in the left
void fun (int x =5, int y)
{
// function body
}
when calling this function
fun(1) // will not work because the compiler can not know to which variable to assign 1. it overrides the default and sets x=1 but there is no argument for y so it raises a syntax error.
0
both of you thanks for responding! I got it now wondwosen :)