Conditional comparison of enum
Is it possible to use enums in a conditional statement, like
typedef enum
{
kUserCapabilites_0 = 0,
kUserCapabilites_1 = 1,
kUserCapabilites_2 = 2
} UserCapabilites;
if (theUsersCapability == kUserCapabilites_2)
where theUsersCapability is one of the saved 开发者_开发问答UserCapabilites
Yes, you can compare. You should have tested instead.
Disclaimer: This should hold for Objective-C too. Please check it.
#include <stdio.h>
typedef enum{
a = 1, b, c
}aa;
int main(){
aa obj = a;
if( obj == b )
printf("Equal");
else
printf("Not Equal");
return 0;
}
Result : Not Equal
Online Result
精彩评论