typedef enum scope in xcode projects
So, my current understanding of enum is that I can use it to make constants that correspond to numbers. So,
typedef enum
{
number0 = 0,
number1 = 1,
.
.
.
} Numbers;
would allow me to refer to 0 as number0 in every part of the code. This seems to work fine. However, I'm having trouble figuring out how to use this in an Xcode Project. For example, say I write one class, NumberCounter
, and include this code in the header file. Then, I write another class, numberCalculator
. If I want to use the same definitions in the second class, do I have to A) write the classes in the same source file, or B) include the above code in every file I want to use the numbers?
If I include the code in one class, and exclude it in the second, I get (when trying to have a function return something of type Numbers
) a Parse Issue Expected a Type error, but if I include the code in both, it gives an error about 'Redefinition of enumerator'. Currently, my workaround is to include the code in every file, then use the preprocessor to make sure it is only executed once - i.e:
#ifndef NumberDef
#define NumberDef
typedef enum
{
number0 = 0,
number1 = 1,
.
.
.
} Numbers;
#endif
This works, but I feel like the开发者_如何学Pythonre should be a nice simple way of doing this. What am I missing here?
Include the header it's defined in.
精彩评论