Originally Posted by
matott
It returns a concatenated string of name and another string. But if the specified name doesn't exist, the function has to indicate this. I could just figure out one solution: throwing an exception. But I think this is not very useful in this case. Can you imagine another solution (like returning iterator::end (), but for strings).
If you want to return a reference, you have to return a reference. There's no such thing as a NULL reference. So, you can either throw an exception, or design your function like this:
Code:
bool find(const string &a, string &b);
It returns the result in the b reference, and returns "true" or "false" to indicate whether it failed. If failure is a common occurrence, this is probably the best method. If failure is very UNcommon, I'd throw an exception instead.
EDIT: I've made the input string const, as it should have been.