这是我当前的设置:
// 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
。我在 header 中声明了作用域枚举,因为 test.cpp
和 main.cpp
最终都需要访问它。
我当前的设置有问题吗?我是 C++ 的新手,所以我可能忽略了一些非常简单的事情。
最佳答案
这种类型的enum
声明需要C++11来编译。
我需要在编译时向 g++ 添加 -std=c++11
标志以确保支持。
关于c++ - 访问在类外声明的作用域枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26089676/