【发布时间】:2011-07-08 11:53:53
【问题描述】:
您好,我有名为 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' is not a class or namespace...
(在 MS VS2010 中运行良好,但在 linux g++ 中运行良好)
有什么想法吗? 谢谢 托马斯
【问题讨论】:
-
注意:在您的
.cpp文件中,如果您想为MyClass::foo提供一个实现,签名将是void MyClass::Foo() { ... }。您缺少MyClass::位。 -
MyCode.h != MyClass.h ... 怀疑这有帮助:P