suppose I have:
void f(bool option1 = false, bool option2 =false, bool option3 = false)
{
...
}
And I want to call:
f(option2=true);
Is this possible in C++?
It is not possible to invoke a function in the manner you suggested in C++. You can emulate named parameters via metaprogramming or simply pass a struct
to your function. E.g.
struct options
{
bool option0{false};
bool option1{false};
bool option2{false};
};
void f(options opts = {});
C++11 usage:
options opts;
opts.option2 = true;
f(opts);
C++2a usage:
f({.option2=true});
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