你好,我有名为MyCode.h和MyCode.cpp的文件。
在MyCode.h中,我已经声明了:
enum MyEnum {Something = 0, SomethingElse = 1};
class MyClass {
MyEnum enumInstance;
void Foo();
};
然后在MyCode.cpp文件中:
#include "MyCode.h"
void MyClass::Foo() {
enumInstance = MyEnum::SomethingElse;
}
但是在使用g++编译时,我收到了错误消息:“MyEnum”不是类或命名空间......
(在MS VS2010中可以正常工作,但在Linux g++中无法工作)
有什么想法吗? 谢谢 托马斯
.cpp
文件中,如果您想为MyClass::foo
提供实现,则签名应为void MyClass::Foo() { ... }
。您缺少了MyClass::
这一部分。 - phooji