Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't understand the reason for "Expected a type" compilation error in a method declaration, when the type is defined

This code won't compile and generates the error message "Expected a type". As the type is declared right above I don't understand why.

enum TMyType
{
    Etype1,
    Etype2
};

@interface Factory : NSObject

+ (void) foo: (TMyType) actionType;

@end
like image 976
Gruntcakes Avatar asked Feb 08 '12 19:02

Gruntcakes


2 Answers

To define a custom type, the correct way is with a typedef.

Try...

typedef enum 
{
    Etype1,
    Etype2
} TMyType;

EDIT: Not long after this question was asked and answered, Apple came out with a new way to do enumerated data types. Here's an in-depth article on it.

typedef NS_ENUM(NSInteger, TMyType) {
    Etype1,
    Etype2
};
like image 133
Jeff Wolski Avatar answered Oct 16 '22 18:10

Jeff Wolski


+ (void) foo: (enum TMyType) actionType;

or use .mm (and retag question with objective-c++).

like image 3
Michael Krelin - hacker Avatar answered Oct 16 '22 18:10

Michael Krelin - hacker