3

我正在尝试编译一个库。

class ROCKETCORE_API Property
{
public:
enum Unit
{
    UNKNOWN = 1 << 0,

    KEYWORD = 1 << 1,           // generic keyword; fetch as < int >

    STRING = 1 << 2,            // generic string; fetch as < String >

    // Absolute values.
    NUMBER = 1 << 3,            // number unsuffixed; fetch as < float >
    PX = 1 << 4,                // number suffixed by 'px'; fetch as < float >
    COLOUR = 1 << 5,            // colour; fetch as < Colourb >
    ABSOLUTE_UNIT = NUMBER | PX | COLOUR,

    // Relative values.
    EM = 1 << 6,                // number suffixed by 'em'; fetch as < float >
    PERCENT = 1 << 7,           // number suffixed by '%'; fetch as < float >
    RELATIVE_UNIT = EM | PERCENT,

    // Values based on pixels-per-inch.
    IN = 1 << 8,                //<<----LINE 66----- number suffixed by 'in'; fetch as < float >
    CM = 1 << 9,                // number suffixed by 'cm'; fetch as < float >
    MM = 1 << 10,               // number suffixed by 'mm'; fetch as < float >
    PT = 1 << 11,               // number suffixed by 'pt'; fetch as < float >
    PC = 1 << 12,               // number suffixed by 'pc'; fetch as < float >
    PPI_UNIT = IN | CM | MM | PT | PC
};

错误输出为:

Property.h:66:6: error: expected identifier before '=' token
Property.h:66:6: error: expected '}' before '=' token
Property.h:66:6: error: expected unqualified-id before '=' token

我认为还有其他错误是由于该枚举未正确定义而引起的。

知道为什么会这样吗?

将 MinGW 4.7.2 与 Eclipse 一起使用。

4

1 回答 1

10

这种情况下的一个典型问题是与您包含的某些标头中定义的某些宏名称发生冲突。在您的情况下IN,它在某些实现(MS?)中用作指定函数中的输入参数的宏。

一个好主意是给你的枚举常量一个前缀,UNIT_UNKNOWN而不是只是UNKNOWN. 或者,您可以#undef IN在包含所有“系统”标头之后执行此操作,但这种方法很容易最终变得非常“高维护”。再次,一个更好的主意是避免使用短的全大写标识符。

于 2013-02-04T21:25:30.977 回答