You can't have a reference to a literal value, therefore having a default argument for a reference doesn't make much sense.
One thing you could do (I don't reccomend doing this because it involves global variables) is make your reference have a default variable to refer to
Code:
#include <iostream>
int default_arg = 10;
void foo(int& bar = default_arg)
{
std::cout << bar << std::endl;
}
int main()
{
int i = 5;
foo(i);
foo();
}
Or, you could just overload your functions (This is a much better solution)
Code:
#include <iostream>
void foo(int& bar)
{
std::cout << bar << std::endl;
}
void foo()
{
std::cout << 10 << std::endl;
}
int main()
{
int i = 5;
foo(i);
foo();
}