开发者

returning enum from function in C++ base class

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜