开发者

Enumerators Cast

I have en error when try to cast own enumerator to address book values:

typedef enum {
    kACTextFirstName = kABPersonFirstNameProperty, // error: expression is not an integer constant expression
    kACTextLastName = (int)kABPersonLastNameProperty, // error: expression is not an integer constant expression
} ACFieldType;

How to solve the problem?

Thank you.


I need to init my enum using A开发者_高级运维BAddressBook's framework const values such as kABPersonLastNameProperty or kABPersonFirstNameProperty.


In C (unlike in C++), an object declared const, even if it's initialized with a constant expression, cannot be used as a constant.

You didn't bother to show us the declaration of kABPersonFirstNameProperty, but I"m guessing it's declared something like:

const int kABPersonFirstNameProperty = 42;

If you need to use the name kABPersonFirstNameProperty as a constant expression, you can either declare it as a macro:

#define kABPersonFirstNameProperty 42

or as an enumeration constant:

enum { kABPersonFirstNameProperty = 42 };

Note that the enum hack only lets you declare constants of type int.

Likewise for kABPersonLastNameProperty.

(And why do you cast one of them to int, but not the other?)

If that doesn't answer your question, it's because you didn't give us enough information.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜