Initialized reference in function
Hey, if I want to have a function that can take a reference value as argument but also have that value initialized if no such value is supplied when calling the function, how would that be done?
I would like something like this (which is not working)
Code:
int Function(float &value = 0.0f);
int Function(float &value)
{
value = 5.0f;
return 1;
}
So that I can call this function in both these ways:
Code:
int vertex = Function();
Code:
float value;
int vertex = Function(value);
I would rather like to avoid function overloading. Is there a way to write the definition of the function to make it work?