Quote:Original post by Extrarius
Posting the exact error would be helpful. I'm going to have to disagree with nmi about the const: I've started labeling all return types const since they should be and I've had no such trouble.
Actually there is no gain from declaring the return value constant because first an expression such as:
foo a = b + c;
where the return type of the overloaded operator returns a constant foo, if the compiler doesn't optimize it will actually create an extra redundant copy because the type of the variable A in the assigment is not a constant type.
secondly the compiler will ignore the fact that the return type is constant or not where immediate results are generated it will always generate a temporary that you can only invoke constant methods of the type in question e.g.
foo a = b + c * d;
so the temporary generated by (c * d) can only invoke constant methods.
So in the end there is no gain from declaring user-defined return type constant and may actually lead to redundant copying if not optimized by the compiler.