开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜