Re:C++ pitfalls
by baobab on Wednesday November 28, 2012 @12:39PM
(#4843693)
With explicit conversion operators you can fix this:
"if (-0.5 <= x <= 0.5) return 0;"
for x that are not built-in types.
You would need to create your own Bool type, something like defined below, and overload <= operators for x type, returning Bool. This way you will get compile time error.
class Bool { bool value; public: Bool(bool v) : value(v) {} explicit operator bool () { return value; } };