我的枚举不是一个类或命名空间 [英] My enum is not a class or namespace

查看:578
本文介绍了我的枚举不是一个类或命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有文件名为MyCode.h和MyCode.cpp

Hi I have files called MyCode.h and MyCode.cpp

在MyCode.h中我已声明

In MyCode.h I have declared

enum MyEnum {Something = 0, SomethingElse = 1};

class MyClass {

MyEnum enumInstance;
void Foo();

}; 

然后在MyCode.cpp中:

Then in MyCode.cpp:

#include "MyCode.h"

void MyClass::Foo() {
    enumInstance = MyEnum::SomethingElse;
}

但是使用g ++编译时得到错误'MyEnum'或命名空间...

but when compiling with g++ I get the error 'MyEnum' is not a class or namespace...

(在MS VS2010中正常,但不是linux g ++)

(works fine in MS VS2010 but not linux g++)


感谢
Thomas

Any ideas? Thanks Thomas

推荐答案

语法 MyEnum :: SomethingElse 是Microsoft扩展。它恰好是我喜欢的一个,但它不是标准C ++。 枚举值添加到周围的命名空间:

The syntax MyEnum::SomethingElse is a Microsoft extension. It happens to be one I like, but it's not Standard C++. enum values are added to the surrounding namespace:

 // header
 enum MyEnum {Something = 0, SomethingElse = 1};

 class MyClass {

 MyEnum enumInstance;
 void Foo();

 }

 // implementation
 #include "MyClass.h"

 void Foo() {
     enumInstance = SomethingElse;
 }

这篇关于我的枚举不是一个类或命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆