Quantcast
Channel: Can (a==1)&&(a==2)&&(a==3) evaluate to true? (and can it be useful?) - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Christian Hackl for Can (a==1)&&(a==2)&&(a==3) evaluate to true? (and can it be useful?)

$
0
0

Operator overloading and macros are trivial solutions to such a riddle.

And if so, can it actually be useful?

Well, with some imagination... One possible use case I can think of are unit tests or integration tests in which you want to make sure that your overloaded operator== for some class works correctly and you know for sure that it works incorrectly if it reports equality for different operands when it's not supposed to do that:

class A {public:    A(int i);    bool operator==(int i) const;    // ...};A a(1);if ((a==1)&&(a==2)&&(a==3)) {    // failed test    // ...}

Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>