I have written a function that returns a string. It works as expected. It looks like this:
1 2 3 4 5 6 7 8
string myFunction (int i, string myString) {
string output;
if (everything==ok) {
return output;
} else {
return"Error";
}
}
Now, if the function fails, I'd rather like to send an integer. How should I do that? Is it possible?
I've read many posts where some people would suggest that I could pass an integer variable as reference and write that variable if the function fails or even pass a struct as reference and use it in such a way as well.
I just want to know what do you people think is the most appropriate (or elegant) way of doing it. Is there may be another way?
One way of doing it is pass the output type by reference, in this case a string, and return error code.
In case if no error return 0, in case or error return the error code.