开发者

Enum declaration in Eclipse

I'm compiling a 开发者_高级运维c++ project in Eclipse, Linux.

The project was compiled in Windows in the past.

I have my declaration of enums like this:

enum nameofenum:UINT32
{
  one=0,
  two=1
}

The result is an error in eclipse.

  1. What is the meaning of :UINT32?
  2. How can I switch this declaration to Linux?

Thanks!!


That looks like a strongly typed enum, which is a C++0x feature. Basically, it specifies the underlying type of the enumeration, so one and two will be UINT32s.

To compile it, you need a compiler that supports this particular part of the C++0x language. I believe GCC 4.4 and Visual C++ supports strongly typed enums to some extent.


The : UINT32 declares the underlying type of the enumeration; it means that the enumeration will be represented by a UINT32.

This is a new C++ feature that is being added in C++0x called strongly typed enumerations. Visual C++ has supported it at least since Visual C++ 2005; the version of g++ you are using may not support it.

As for how you get this working with g++, it depends. If you don't have any code that relies on a particular underlying type, then you can just remove it. If you do have code that relies on a particular underlying type, you might consider replacing uses of the enumeration type with the underlying type (i.e., use UINT32 instead of nameofenum); this isn't very nice, though.


  1. UINT32 is unsigned 32bit integer, so your enum is representated by 4bytes int.
  2. It depends. I dont' know exactly, but do you really need to use this enum as 32bit int? May be you just can avoid this :UINT32 declaration?


: UINT means that the underlying type of the enumeration identifiers is UINT. It is a Microsoft extension described here. To make it compile remove : UINT.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜