Reputation: 439
I have an enum declaration as below.
//declaring the situations can happen by next step
enum step {CANGO, CANTGO, WILLFALL, LOSEPOINT, GAINPOINT};
and I want to delcare a function which its output is of that declared enum. How I can do that?
Upvotes: 0
Views: 66
Reputation: 98388
Easy:
enum step myfunction();
Or if you want you could use typedef
, but I wouldn't recommend it in this case:
typedef enum step step;
step myfunction();
The trick to remember is that in C, an enum type must be referred to using the enum
keyword, so a plain step
would not work, which is probably what you tried first.
Of course, with the typedef
trick it works. You can be even lazier and write:
typedef enum step {CANGO, CANTGO, WILLFALL, LOSEPOINT, GAINPOINT} step;
But I'm on the opinion that an enum must look like an enum (a struct like an struct, and so on), and this typedef
hides that.
Upvotes: 4