所以在学习c++之前,我已经对c#语言有了相当的经验。在 C# 中,我能够为程序创建一个包含枚举的枚举类。我想知道,如何在 C++ 中创建一个枚举类。我正在使用 netbean 8.2 编写代码。我对枚举类的意思不是类中的枚举而是整个类本身就是枚举。
编辑:我已经想通了。感谢所有提供帮助的人。
最佳答案
我们可以简单地这样做:
int main()
{
enum class Color // "enum class" defines this as a scoped enumeration instead of a standard enumeration
{
RED, // RED is inside the scope of Color
BLUE
};
enum class Language
{
ENGLISH, // ENGLISH is inside the scope of Language
ITALIAN
};
Color color = Color::RED; // note: RED is not directly accessible any more, we have to use Color::RED
Language language = Language::ENGLISH; // note: ENGLISH is not directly accessible any more, we have to use Language::ENGLISH
}
关于c# - 如何在 C++ 中创建枚举类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58745552/