It is unclear why you think this would be needed. What would be the "out" when the default is used?
You can overload functions:
void FunctionTest(int param1,int& param2) {
param2 = 20;
}
void FunctionTest(int param1) {}
int main() {
int a = 100;
int b = 200;
FunctionTest(10);
FunctionTest(a, b);
}
However, I cannot imagine this to be a good use case for overloading, because the two calls do something very different.
Only for the sake of completeness. A default arguemnt for reference can be a global:
int foo;
void function(int& b = foo);
Or a function local static or static class member:
struct moo { static int x; }
void function(int& b = moo::x);
int& bar() {
static int x = 0;
return x;
}
void function(int& b = bar::x);
Or more generally a function that returns a (valid) reference to any of the above.
int foo = 10; void FunctionTest(int param1, int& param2 = foo) . . .is just fine. `