I am new to c++ and trying to learn how to use the optional parameters in functions.
Right now I know that you can make a function with optional parameters like this:
void X_plus_Y(int x=10, y=20) {return x + y;}
int main() {
X_plus_Y(); // returns 30
X_plus_Y(20); // set x to 20 so return 40
X_plus_Y(20, 30); // x=20, y=30: return 50
return 0;
}
But I've searched the internet and didn't find any way to pass optional arguments like this:
X_plus_Y(y=30); // to set only the y to 30 and return 40
Is there a way or a "hack" to achieve this result?
std::optional, etc.