我的問題是在代碼中,但基本上我想知道如何/如果我可以做兩條註釋掉的線?我知道我可以在構造函數中完成,但我不想!如何初始化一個數組中的數組而不分別執行每個元素? (C++)
struct foo
{
int b[4];
} boo;
//boo.b[] = {7, 6, 5, 4}; // <- why doesn't this work? (syntax error : ']')
//boo.b = {7, 6, 5, 4}; // <- or else this? (syntax error : '{')
boo.b[0] = 7; // <- doing it this way is annoying
boo.b[1] = 6; // :
boo.b[2] = 5; // :
boo.b[3] = 4; // <- doing it this way is annoying
boo.b[4] = 3; // <- why does this work!
(使用:C++,Visual Studio 2005中)
這是另一種場合,可以宣傳即將推出的C++ 11標準的統一初始化語法...... – sbi 2010-05-14 15:51:08