Operator overloading and different types

前端 未结 5 1541
轮回少年
轮回少年 2021-01-04 09:33

I have a class Score which is going to be heavily used in comparisons against integers. I was planning on overloading the == operator to enable these comparisons as per th

5条回答
  •  感动是毒
    2021-01-04 10:16

    Usually when I see an overloaded operator, it comparisons of that class to itself. So if you have multiple instance variables, you would figure out how to compare the two to determine if something was equal, greater, less, etc.

    I don't see why you don't just do:

    if(myScore.value == 5)
    {
     //do stuff
    }
    

提交回复
热议问题