在不同的类Objective-C中具有相同名称的typedef

时间:2013-12-09 12:04:15

标签: ios objective-c syntax enums typedef

我有这种typedef:

//MyClass_1.h

typedef enum
{
   edit,
   copy,
   paste
} textAction;

当我在MyClass_2.h中想要这个typedef:

//MyClass_2.h

typedef enum
{
   edit,
   copy,
   paste
} textAction;

我有错误:Typedef重新定义类型('enum textAction'vs'enum textAction')。在MyClass_2.h中,我没有使用#import MyClass_2!为什么我有这个错误?

1 个答案:

答案 0 :(得分:2)

在两个类中使用相同的枚举。 将枚举放在.h文件中,并将其包含在其他.h中 这样就为编译器准备了完全相同的枚举。

你使用它的方式,它是链接器/编译器和东西的两个不同(但看起来相同)的枚举。

相关问题