0
我無法編譯底部的代碼。我這樣做是C
所有的時間,但是當它是一個類中不能做到這一點在C++
。有人能告訴我這裏有什麼問題嗎?如何在類中定義struct?
class Parser {
struct table {
string first;
string second;
string third;
} c_table [] = {
"0","a","b",
"0","c","d",
"0","e","f",
};
};
int main() {
return 0;
}
test.cpp:22:3: error: too many initializers for ‘Parser::table [0]’
test.cpp:22:3: error: could not convert ‘(const char*)"0"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"a"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"b"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"0"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"c"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"d"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"0"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"e"’ from ‘const char*’ to ‘Parser::table’
test.cpp:22:3: error: could not convert ‘(const char*)"f"’ from ‘const char*’ to ‘Parser::table’
麻煩編譯意味着你應該包括完整的錯誤。 – chris
你使用C++ 11嗎? – jrok
@chris:我已經包含錯誤 – Mark