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;
}
这篇关于我的枚举不是类或命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我的枚举不是类或命名空间
基础教程推荐
- c++ STL设置差异 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
