如何在结构C++中使用枚举
How to use enum in structure C++
我试图在结构中使用enum,但我得到了以下错误:
union.cpp:27:21: error: ‘DOLLAR’ was not declared in this scope
book.currency = DOLLAR;
^
这是我的代码:
struct shelf{
char title[50];
char author[50];
union {
float dollars;
int yens;
};
enum {
DOLLAR = 1, YEN
} currency;
} book;
int main () {
strcpy(book.title,"book 1");
strcpy(book.author, "author 1");
book.dollars = 100;
book.currency = DOLLAR;
cout << book.currency;
return 0;
}
book.currency = DOLLAR;
应该是
book.currency = shelf::DOLLAR;
相关文章:
- 不带大括号的枚举形式
- 枚举环境变量的惯用C++14/C++17方法
- 类似枚举的计算常量
- 如何正确实现和访问运算符的各种自定义枚举器
- 错误:从"int"到枚举c++的转换无效
- C++中构造函数中的枚举
- 访问在 C++ 结构中声明的枚举变量
- 枚举类'classname'的多重定义
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- typedef 枚举和枚举类有什么区别?
- 为什么我的开关/机箱在使用枚举时默认?
- 标准::可选枚举的比较运算符
- C++两个源文件之间共享的枚举的静态实例
- 打印没有铸件的枚举可以在C++中吗?
- 枚举成员与静态 int 成员?
- C++:枚举:错误:应使用标识符而不是"}"
- 带有 c++ 的枚举(输入检查)
- 在 qml 中使用 Q_ENUM 和 Q_PROPERTY 作为枚举类
- 为什么 int 类型的枚举类值不能用作 int
- 在 C++ 中输出枚举类类型的向量元素