2016-10-28 127 views
2

你好,我是C++的新手。 對於我的項目,我需要使用類似C#示例的枚舉值。C++枚舉結構錯誤的定義

我的結構

struct Rows 
{ 
    string name; 
    bool primaryKey; 
    int lenght; 
    string defined; 
    MyLDC::Attributes attrib; 
    bool Nullable; 
    bool AutoIncrement; 
    string comment; 

}; 
Rows rw; 
Rows* row = &rw; 

MyLDC ::屬性

enum Attributes 
{ 
    _BINARY = 0x26, 
    _UNSIGNED = 0x27 
}; 

我的實施例功能

void MyLDC::CreateTable(string tablename,string primaryKey) 
{ 

    //Simple Row Implementation 
    row->name = "Example Row"; 
    row->AutoIncrement = true; 
    row->primaryKey = true; 
    row->comment = "Example Row"; 

    row->attrib = Attributes::_UNSIGNED; 

我上行級別>屬性=獲取錯誤屬性:: _ UNSIGNED;

不知道這個錯誤。 誰是正確的解決方案?

+2

而且*你得到了什麼*錯誤?請在問題主體中提供完整的和未經編輯的錯誤。 –

+0

與您的錯誤無關,爲實現(編譯器和標準庫)保留以下劃線開頭且後跟大寫字母的符號名稱。見例如[這個老的答案的更多信息](http://stackoverflow.com/a/228797/440558)。 –

+0

錯誤:屬性'不是類或名稱空間| –

回答

1
enum Attributes 
{ 
    _BINARY = 0x26, 
    _UNSIGNED = 0x27 
}; 
... 
row->attrib = Attributes::_UNSIGNED; 

我的心靈調試權力;)告訴我,問題是,_UNSIGNED符號不是Attributes的範圍之內,所以你應該能夠做到:

row->attrib = _UNSIGNED; 

對於作用域枚舉你可能想要使用C++ 11的enum class

P.S.還請注意_Upper(下劃線後跟大寫字母)名稱爲保留用於實現,不應在您的代碼中使用。

+0

很棒Mr.C64哇真的很好。 –

+0

@JoeMartiniello:很高興能有一些幫助。我之前去過那裏:) –

+0

對不起,我沒有得到。這似乎是在我的情況下工作:http://ideone.com/4KyrH6我在做什麼不同? –