I’m writing a class that represents an ordinal scale, but has no logical zero-point (eg time).
This scale should permit addition and substraction (operator+, operator+=, …) but not multiplication.
Yet, I always felt it to be a good practice that when one overloads one operator of a certain group (in this case the math operators), one should also overload all the others that belong to that group. In this case that would mean I should need to overload the multiplication and division operators also, because if a user can use A+B he would probable expect to be able the other operators.
Is there a method that I can use to throw an error for this at compiler time? The easiest method would be just no to overload the operators operator*, … yet it would seem appropriate to add a bit more explaination than operator* is not know for class "time".
Or is this something that I really should not care about (RTFM user)?
Wrong. The only groups are things like
+and+=– and then maybe-and-=. “Arithmetic operators” in general is not a group. Consider something likestd::string.