c++ - Defining a proper subtraction operator -
I wrote an abstract class for a math object, and defined all operators. When using it, I came across:
Fixed F1 = 5.0 F - F3;
I have only definition of two subtraction operators:
inline conic fixed operator - () cons; Inline conic fixed operator - (float F) console;
What's wrong with me here - the additional is swapable (1 + 2 == 2 + 1) while there is no subtraction (this also goes for multiplication and division). I immediately wrote a class outside in this way:
Fixed inline static operator - (float F, CONST fixed and FP);
But then I realized that this can not be done, because for doing so I have to touch the class personal, which is to use the keyword friend
As a result of I, the namespace is polluted with 'stable' redundant function.
Error: 'Fixed Constraints Fixed Fixed: Operator- (Float, Constant & Fixed; Amp;) 'should either be a non-static member function or non-member function.
According to the suggestions suggested by GCC, a non-static task is the result of the following error:
Error: 'Fixed Fixed Fixed :: Operator- (Float, Constant & amp; nbsp;) should take zero or one argument
Why can not I define the same operator within the class definition? If there is no way to do this, then is not anyone using the friend
keywords anyway?
The same question goes for division, because it suffers from the same problem.
Comments
Post a Comment