Can a function have more than one default parameter? Like maybe:
If it is possible, how do I use only one of them (e.g. from the code above I just used the default test2=0 and set the state to false)?
void methodA(int test, int test2=0, bool state=true);
void A::methodA(int test, int test2, bool state)
Thanks in advance.
I would imagine that would cause ambiguity. I'd just put in the default explicitly for the middle argument. Perhaps for the same reason that
>>When a default is provided, all remaining parameters must be given defaults. There can not be any holes.
Similarly, once a default is "used" in a call, all others must be default as well.
However, I am entirely unsure. You'd think that type-checking might make this possible, but if they're the same type.. if an implicit cast would work... I don't think you can do it.
I believe they are considering adding to the next standard the ability to specify which function parameter an argument refers to. I don't remember if this is only for template arguments or for function arguments, though. Until then, if you want to use the default value for one parameter, you have to use the default for all the rest after it. And if you don't want to use the default for a parameter, you have to specify a value for all the rest before it.