How to parse function arguments, when all have default values and only some of them are used? Example: I have a function with several arguments with default values
void fun(string a="", int b=0, string c="", int d=0)
{
//parse used arguments somehow
}
I want to use it with different value of arguments, for example:
fun("foo", 10);
fun(10, 10);
How can I determine which arguments were used? Maximum value of arguments is known and order will be always the same. I do not want to run function like:
fun("", 3, "", 10);
And I cannot use variadic functions.
Any ideas?
fun(10, 10);will either not compile as 10 is not a string, or will not do what you expect (it'll probably assume 10 is a pointer to a char*)std::stringdeliberately made sure of that.foo(0, 10);which is a really nasty bug source in this case.