How do i assign a default value to a bool that is a reference?
I have a function like this :
void someFunction(bool a = true, bool& b)
{
if(a)
b = false;
else
std::cout << "nothings changed" << std::endl;
}
How should i assign the default value to b in this context?
void someFunction(bool a = true, bool& b = false)
will not work. So how should it be done?
You cannot initialize non-const references with values. You need a variable:
But it would probably make a lot more sense to simply return the bool:
Then the client can still decide for himself if he wants to ignore the result or not.