2013-02-04 58 views
2

我正在嘗試編譯一個庫。錯誤:'='令牌之前的預期標識符

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 

而且有我相信通過此枚舉沒有被正確定義造成其他錯誤。

任何想法爲什麼發生這種情況?

在Eclipse中使用MinGW 4.7.2。

+1

這個枚舉編譯得很好。你如何使用它? – chris

+3

哪一行是66? – AnT

+0

我應該整個文件嗎? – Etherealone

回答

8

在這種情況下,一個典型的問題是與您包含的某個頭文件中定義的某個宏名稱衝突。在你的情況下,將是IN,在某些實現中(MS?)用作指定函數中輸入參數的宏。

一個好主意是給你的枚舉常量前綴,如UNIT_UNKNOWN而不是隻是UNKNOWN。或者,在包含所有「系統」頭文件後,您可以執行#undef IN,但這種方法很容易導致非常「高維護」。一個更好的主意是再次避免使用短全帽標識符。

+0

來吧,這不是一個正確的答案。這應該是一個評論。 – antonijn

+2

考慮到錯誤消息,這可能是一個原因。 – chris

+0

@chris最新的編輯阻止了我的投票。 – antonijn

相關問題