访问在类外部声明的作用域枚举
Accessing scoped enums declared outside classes
这是我当前的设置:
// test.h
enum class test_t {ONE, TWO, THREE, FOUR};
// test.cpp
#include "test.h"
// main.cpp
#include "test.h"
test_t thing = test_t::ONE;
但是,当我尝试在main.cpp
中创建枚举对象时,我得到了error: expected a class or namespace
。我在头中声明了作用域枚举,因为test.cpp
和main.cpp
最终都需要访问它。
我目前的设置有问题吗?我对C++很陌生,所以我可能忽略了一些非常简单的东西。
这种类型的enum
声明需要C++11进行编译。
在编译时,我需要将-std=c++11
标志添加到g++中,以确保有支持。
相关文章:
- 将作用域枚举转换为基础类型
- 无法让"std::enable_if"适用于无作用域枚举
- 为什么不能直接引用作用域枚举类成员,而不能为无作用域枚举生成类成员?
- 错误:表达式必须具有算术、无作用域枚举或带有运算符重载的指针类型
- 作用域枚举和标准::get
- 如何确保 Visual C++ 不允许作用域枚举访问?
- C++/错误:表达式必须具有整数或无作用域枚举类型
- C++ 在方程中使用变量;错误:表达式必须具有整数或无作用域枚举类型及其他
- 防止作用域枚举可复制/可移动
- 错误:以增量方式填充向量时,表达式必须具有整数或无作用域枚举类型
- 无作用域枚举的基础类型?
- 有效的双向作用域枚举映射
- 错误:数组大小表达式必须具有整型或无作用域枚举类型,而不是'double'
- 为什么作用域枚举默认支持运算符'<'?
- 无作用域枚举、枚举器和基础类型C++中的歧义
- 为什么要编译无作用域枚举的声明?
- 具有作用域枚举的位集无法编译
- 如何重载作用域枚举的运算符>?
- 无作用域枚举是否仍然有用
- 表达式必须具有整数或无作用域枚举类型,并带有字符串向量