How do I compare 2 integers without getting warnings?
I have a va开发者_如何学Criable Player1Visits
which is declared as int
.
If I try to compare this to 1 using Player1Visits == 1
I get the warning comparison between integer and pointer. Should I be using a different type?
I would double-check what Player1Visits is declared as; if you're getting that compiler warning, it is almost certainly not an int
. Likely possibilities include what @aronchick said, where Player1Visits is an int*
(a pointer to an int), so you want to compare using:
*Player1Visits == 1
Another possibility is that Player1Visits is some kind of object with an int
property, where you want to figure out what property name you want and call:
[Player1Visits someIntProperty] == 1
(This last assumes you're using Objective-C, which is (I believe) a not-unreasonable assumption given your choice of IDE.)
You haven't declared it as int
, the compiler warning gives that away. Perhaps you've declared it as NSInteger *Player1Visits;
or int *Player1Visits;
.
If you declared it that way, remove the *
.
Don't you mean to compare:
*Player1Visits == 1
精彩评论