I apoligise for the enigmatic title
This is not for any specific project, I''m just curious how one would create a default value for a parameter passed as a referenced.
For example, say I have a function called MyFunction(), defined like so:
bool
MyFunction (int& r_iNumber_)
{
r_iNumber_ = iSomeValue;
return true;
}
This function does two things: it sets the input to a value and returns something that in real life would depend on the value of the input.
I want the input, r_iNumber_, to be optional. I.E. the user could forgoe the extra functionality if it wasn''t required.
The only way I know how to do this is to make the parameter a pointer, have the function part of a class and have it declared as such:
class MyClass
{
public:
bool MyFunction(const int* c_piNumber_ = NULL);
}
Then if a parameter was not given, c_piNumber_ would equal NULL, allowing me to check if a parameter was specified, using something like:
if (c_piNumber_)
{
// number was specified, modify
}
I want to do the same thing, but with references. How do you set a reference to ''NULL'', as it were, so you can check whether or not it has been set?
Or maybe there''s a better way to do this altogether?
All help is greatly appreciated.
The_Minister
1C3-D3M0N Interactive