Can (a==1)&&(a==2)&&(a==3) evaluate to true? (and can it be useful?)

前端 未结 8 1343
北荒
北荒 2021-01-15 11:34

Inspired by another question regarding java-script language. Can the expression

 (a==1)&&(a==2)&&(a==3)

evaluate to true i

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 12:13

    Yes it can:

    class Foo
    {
        public:
        bool operator==(int a)
        {
            return true;
        }
    };
    

    Then, let a be of type Foo and voila.

    Can this actually be useful? I don't really see it being useful no.

提交回复
热议问题