If I have something like the following in a header file, how do I declare a function that returns an enum of type Foo?
enum Foo { BAR, BAZ };
Can I just do something like the following?
Foo testFunc() { return Foo.BAR; }
Or do I need to use typedefs or pointers or something?
In C++, you could use just
Foo.In C, you must use
enum Foountil you provide a typedef for it.And then, when you refer to
BAR, you do not useFoo.BARbut justBAR. All enumeration constants share the same namespace (the “ordinary identifiers” namespace, used by functions, variables, etc).Hence (for C):
Or, with a
typedef: