你好,我一个项目中遇到了这个问题里面,我有这样的事情:(C++)不能引用枚举类命名空间
types.h中
namespace Machine
{
enum class size{
TINY,
SMALL,
MEDIUM
}
//other stuff.....
,并在另一个文件:
test.h:
#include "types.h"
class sample{
public:
void some_function();
Machine::size s; //this declaration is correct
}
TEST.CPP:
#include "test.h"
void some_function(){
s = Machine::size::TINY;//line aaaa; this line is error
}
在行AAAA我一直得到错误信息:
error: 'Machine::size' is not a class or namespace
任何人有任何想法,为什么?或者将enum类放在命名空间内不好吗? 谢谢!
Edit: I fixed the machine spell problem in the first file, sorry about that
机::大小S只是为了保持这个属性(一台机器的大小)的地方,所以我真的不认为这是一些特别的东西。
在您的第一台文件机器中是下划线。是否打算 – Eric
请不要使用接受的答案解决您的问题。任何后来阅读这篇文章的人都会感到困惑。我回到了以前的修订版,以便问题和答案有意义。 – paddy