3

I came across the following code,

class Handler
{
public:
   Handler() {}
   ~Handler() {}

    enum HANDLER_PRIORITY {PRIORITY_0, PRIORITY_1, PRIORITY_2};

    virtual HANDLER_PRIORITY GetPriority();
private:
    HANDLER_PRIORITY m_priority;
}

in the .cpp file I have this

HANDLER_PRIORITY Handler::GetPrioity()
{
   return PRIORITY_0;
}

I get a compilation error, "missing type specifier - int assumed. Note: C++ does not support default-int"

I know that unlinke C, C++ does not support default-int return. but why would it not recognize an enum return type. It works fine if I replace return type from HANDLER_PRIORITY with int/ void, OR if I define the method in the class itself. (inline) OR change the return type to Handler::HANDLER_PRIORITY.

I am on VS 2008.

Vink
  • 1,019
  • 2
  • 9
  • 18

1 Answers1

21

You need

Handler::HANDLER_PRIORITY Handler::GetPriority()
{
...
}

Edit: Sorry didn't see the rest of your post. As for why this is the case, HANDLER_PRIORTY doesn't have global scope. It's a member of Handler no less than any other. So of course you have to tell the compiler where it is, i.e. use Handler::.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
Matt Phillips
  • 9,465
  • 8
  • 44
  • 75