在Objective-C中使用枚举作为外部文件中的参数? [英] Using enums as parameters in an external file in Objective-C?
问题描述
我在文件foo.h中有一个名为RandomEnum的枚举:
I have an enum named RandomEnum in file foo.h:
// foo.h
typedef enum RandomEnum {
ran_1 = 0,
ran_2
} RandomEnum;
在另一个文件bar.h中,我试图使用RandomEnum作为参数类型: / p>
In another file, bar.h, I'm trying to use RandomEnum as a parameter type:
// bar.h
#import "foo.h"
@interface bar : NSObject {}
-(RandomEnum)echo:(RandomEnum)ran;
@end
但是,编译器似乎没有识别到RandomEnum。是否可以这样做?
However, the compiler doesn't seem to recognize RandomEnum. Is doing this even possible?
编译器错误:
error: expected ')' before 'RandomEnum'
编辑:添加foo.h代码进行澄清
Added code for foo.h for clarification
推荐答案
事实证明这是可能的。我的问题是与不直接但仍然存在的奇怪的交叉包含有关。
It turns out this is possible after all. My problem had to do with odd cross-includes that weren't direct, but were still present.
在给定的示例中,foo.h包含了thing.h,其中包括something.h其中包括bar.h.这个交叉依赖关系是最终的问题。
In the given example, foo.h included thing.h which included something.h which included bar.h. This cross dependency is what ended up being the problem.
仍然很好的知道编译器的错误。感谢您的回应!
Still, good to know for compiler bugs. Thanks for the responses!
这篇关于在Objective-C中使用枚举作为外部文件中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!