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 ABAddressBook’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:If you need to use the name
kABPersonFirstNamePropertyas a constant expression, you can either declare it as a macro:or as an enumeration constant:
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.