returning enum from function in C++ base class

16,311

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::.

Share:
16,311
Vink
Author by

Vink

Updated on June 13, 2022

Comments

  • Vink
    Vink almost 2 years

    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.