How do I indicate that a class doesn't support certain operators?

Posted by romeovs on Stack Overflow See other posts from Stack Overflow or by romeovs
Published on 2012-06-07T20:38:30Z Indexed on 2012/06/07 22:40 UTC
Read the original article Hit count: 185

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)?

© Stack Overflow or respective owner

Related posts about c++

Related posts about error-handling