Because of the unstability of floating points getting compared, I want to have at least a warning when using the comparison operator.
Example:
float a,b;
a == b; // Here the warning shall be thrown
How can I realize that?
I thought of overloading like:
inline bool operator==(const float& a, const float& b)
{
#warning "Usage of equal on floating point variables not allowed."
return false;
}
I didn't found it clear stated, but it seems that overriding of this operator is forbidden as MSVC throws C2803 and gcc throws "must have an argument of class or enumerated type" (also described in Global overloading of == and != for floating-points). Even if it would be possible, the compiler would throw an error when he comes across the #error statement even if not used.