Say I need to return two things from a Validate function: an error code (every time, can be 'ok') and an error message (only if not ok). Exceptions are not appropriate here. At present this is done by returning the int code, and having an errorMessage_ field inside the object, which is looked at by a parent object if the validation fails. Problem is, this prevents the Validate function from being const (which it ideally would be), unless we declare errorMessage_ to be mutable (which seems inappropriate).

I can think of a few ways out of this:
1) status quo
2) pass in a non-const string reference into the validate function, which is populated if needed.
3) Declare an int + string struct, and return that.
4) Declare an ErrorState object (which we may find useful for holding other data), and return that.

2 would be ugly, 3 is simple but would add the cost of a lot of empty strings being constructed, 4 might get a bit expensive for ok states being returned from many validate functions - have a singleton 'ok' which is returned unless there is an error? Null object pattern? I guess 3 and 4 are very similar in principle.

Is there a cleverer way of doing this?