我遇到了以下代码,
class Handler { public: Handler() {} ~Handler() {} enum HANDLER_PRIORITY {PRIORITY_0, PRIORITY_1, PRIORITY_2}; virtual HANDLER_PRIORITY GetPriority(); private: HANDLER_PRIORITY m_priority; }在.cpp文件中我有这个
in the .cpp file I have this
HANDLER_PRIORITY Handler::GetPrioity() { return PRIORITY_0; }我收到一个编译错误,缺少类型说明符 - int假设注意: C ++不支持default-int
I get a compilation error, "missing type specifier - int assumed. Note: C++ does not support default-int"
我知道不连接C,C ++不支持default-int返回。但是为什么它不能识别枚举返回类型。如果我使用int / void替换HANDLER_PRIORITY的返回类型,或者如果我在类本身中定义方法,它可以正常工作。 (内联)或将返回类型更改为Handler :: HANDLER_PRIORITY。
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.
我在VS 2008上。
I am on VS 2008.
推荐答案您需要
Handler::HANDLER_PRIORITY Handler::GetPriority() { ... }编辑:抱歉没看到你的帖子的其余部分至于为什么会这样, HANDLER_PRIORTY 没有全局作用域。它是 Handler 的成员,不低于任何其他。所以当然你必须告诉编译器它在哪里,即使用 Handler :: 。
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::.
更多推荐
从C ++基类中的函数返回枚举
发布评论