Alex Rivera | Logout

Using enums as parameters in an external file in Objective-C?

Asked 2009-12-29T21:59:27.660
9

I have an enum named RandomEnum in file foo.h:

// foo.h
typedef enum RandomEnum {
  ran_1 = 0,
  ran_2
} RandomEnum;

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

However, the compiler doesn't seem to recognize RandomEnum. Is doing this even possible?

Compiler Error:

error: expected ')' before 'RandomEnum'

Edit: Added code for foo.h for clarification

Edit
Report

1 Answer

12

The C construct enum RandomEnum does not define a type called RandomEnum — it defines a type called enum RandomEnum. To be able to write just RandomEnum for the type, you need to use a typedef.

answered 2009-12-29T22:18:17.540

Your Answer