My enum is not a class or namespace

来源:互联网 发布:ps dr3插件for mac 编辑:程序博客网 时间:2024/06/05 09:47

http://stackoverflow.com/questions/5188554/my-enum-is-not-a-class-or-namespace


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

In MyCode.h I have declared

enum MyEnum {Something = 0, SomethingElse = 1};class MyClass {MyEnum enumInstance;void Foo();}; 

Then in MyCode.cpp:

#include "MyCode.h"void MyClass::Foo() {    enumInstance = MyEnum::SomethingElse;}

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

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

Any ideas?ThanksThomas

+++++++++++++++++++++++++++++


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; }


0 0
原创粉丝点击