Initialising reference params
This is a class that needs to return a value (result) by reference as this value indicates the error number if the member functions return false... or the actual result if the member functions return true.
When a RpnEvaluator object is created, it is passed a character string (to be evaluated) and a result.... this result variable has to be a reference param (for the reasons stated)
This is the function that creates the object...
Code:
bool evaluate(char* expr, int &result) {
RpnEvaluator Z(expr, result);
return (Z.Evaluate());
}
The first line cannot be changed as the main function which calls this is the one that acts on the result variable (which is why it's passed by reference)... I can't change the main function or how this function is called.
I cannot for the life of me figure out how to pass 'result' to my class so that it's member functions act on the original variable declared in main and not a copy... the closest I think I got gave me this error message...
Quote:
In method `RpnEvaluator::RpnEvaluator(char *, int &)':
warning: uninitialized reference member `RpnEvaluator::result'
But then I couldn't figure out how to initialise it to zero... didn't like being passed an int.
Any help would be greatly appreciated... thanks...