Returning an enum from a function in C?

后端 未结 4 1688
醉酒成梦
醉酒成梦 2020-12-14 00:51

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
};
         


        
4条回答
  •  -上瘾入骨i
    2020-12-14 01:35

    enum Foo
    {
       BAR,
       BAZ
    };
    

    In C, the return type should have enum before it. And when you use the individual enum values, you don't qualify them in any way.

    enum Foo testFunc()
    {
        enum Foo temp = BAR;
        temp = BAZ;
        return temp;
    }
    

提交回复
热议问题