问题标签 [enum-class]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
5479 浏览

c++ - typedef 和 enum 或 enum 类

我有一个这样的枚举:(实际上,它是一个枚举类)

我希望能够将 my_true 暴露给全局命名空间,这样我就可以这样做:

或者至少:

而不是这个:

这可能吗?

我尝试过这样的事情:

我收到错误:枚举类 truth_enum 中的 my_true 未命名类型

我的猜测是 my_true 是一个值而不是一个类型。我可以做些什么来在我的程序中启用此功能吗?

不理想,但我可以做类似的事情:

0 投票
1 回答
715 浏览

c++ - 将遗留 c 枚举包装到 c++11 枚举类

我有一个旧的 C 库,我必须将它包装在 C++ 环境中。我使用 C++11enum class是因为它们非常有用,而且我想将原始版本enum转换为新版本enum class,而不是简单地创建新enum class版本并重写它。我想做一些像typedef旧C一样的事情:

one_t必须完全可以通过其范围访问,num_t::two就像我可以访问新的 C++11 一样enum class

0 投票
1 回答
2393 浏览

c++ - 如何使枚举类与“位或”功能一起使用?

我通常使用enum'位或'或|一起来允许一个对象有一些选项。如何使枚举类与“位或”功能一起使用?

0 投票
7 回答
53978 浏览

c++ - Can't use enum class as unordered_map key

I have a class containing an enum class.

Then, when I implement the following code in another class...

...I get a compile error.

What is causing the error here?

0 投票
1 回答
24734 浏览

c++ - 前向声明枚举类不起作用

在 State.h 我有

在 State.cpp 我有

问题是任何包含的类State.h都有前向声明,但我不能enum在任何 cpp 文件中使用任何值,除了States.cpp(定义它),比如StateID::MainMenuID. 错误说...

/home/lee/Projects/SuddenAwakening/Source/Game.cpp:24:错误:“MainMenuID”不是“StateID”的成员

我正在运行 LinuxMint15KDE、g++ 4.7,并且我在 nullptr、unique_ptr 等其他部分使用 c++11 功能,所以并不是我忘记了 c++11 的编译器标志。

0 投票
3 回答
3008 浏览

c++ - 将枚举类变量重新解释为基础类型的引用是否安全?

我曾经见过reinterpret_cast将增量应用于枚举类,我想知道这种用法在标准 C++ 中是否可以接受。

我知道在普通类的情况下,转换为基类的引用是安全的。但是由于枚举类不是事件隐式转换为它们的底层类型,我不确定上面的代码是否以及如何保证在所有编译器中工作。有什么线索吗?

0 投票
3 回答
955 浏览

c++ - enum class in c++ can not compile in Mac, while works in Windows

it seems there are some problems with my g++ 4.2 compiler in my Mac. I defined a enum class as follows.

It can compile and run in VS2013 but failed to compile in my Mac (expected identifier or '{'). Is that the problem of my g++? How to upgrade it?

0 投票
1 回答
9372 浏览

c++ - 范围枚举的详细类型说明符不得使用“类”关键字

我有以下枚举规范:

g++ 4.8.1 给出以下错误:

警告:作用域枚举的详细类型说明符不得使用“类”关键字

这是什么原因造成的?

0 投票
1 回答
693 浏览

c++ - 使用 boost::property_tree 从 xml 到 c++ 程序的枚举输入

如何使用该boost::property_tree库从 XML 文件中读取枚举类?

我想避免将其作为字符串读取并将字符串映射到我程序中的枚举类。

0 投票
2 回答
2049 浏览

c++ - 如何从 boost::property_tree 获取枚举?

如何从 a 获取枚举boost::property_tree

这是我的“非工作”示例。

配置文件

主文件

编译输出