My enum is not a class or namespace(我的枚举不是类或命名空间)
问题描述
我有名为 MyCode.h 和 MyCode.cpp 的文件
Hi I have files called MyCode.h and MyCode.cpp
在 MyCode.h 中我已经声明
In MyCode.h I have declared
enum MyEnum {Something = 0, SomethingElse = 1};
class MyClass {
MyEnum enumInstance;
void Foo();
};
然后在 MyCode.cpp 中:
Then in MyCode.cpp:
#include "MyCode.h"
void MyClass::Foo() {
enumInstance = MyEnum::SomethingElse;
}
但是当使用 g++ 编译时,我收到错误MyEnum"不是类或命名空间...
but when compiling with g++ I get the error 'MyEnum' is not a class or namespace...
(在 MS VS2010 中工作正常,但在 linux g++ 中无效)
(works fine in MS VS2010 but not linux g++)
有什么想法吗?谢谢托马斯
Any ideas? Thanks Thomas
推荐答案
语法 MyEnum::SomethingElse
是 Microsoft 的扩展.它恰好是我喜欢的一种,但它不是标准 C++.enum
值被添加到周围的命名空间:
The syntax MyEnum::SomethingElse
is a Microsoft extension. It happens to be one I like, but it's not Standard C++. enum
values are added to the surrounding namespace:
// header
enum MyEnum {Something = 0, SomethingElse = 1};
class MyClass {
MyEnum enumInstance;
void Foo();
}
// implementation
#include "MyClass.h"
void Foo() {
enumInstance = SomethingElse;
}
这篇关于我的枚举不是类或命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我的枚举不是类或命名空间


- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01