是否有可能與const成員有匿名聯合?我有以下幾點:構造函數和與const成員的匿名聯合
struct Bar {
union {
struct { const int x, y; };
const int xy[2];
};
Bar() : x(1), y(2) {}
};
隨着G ++ 4.5我得到的錯誤:
error: uninitialized member ‘Bar::<anonymous union>::xy’ with ‘const’ type ‘const int [2]’
'struct {const int x,y; };'是無效的C++。你問你是否可以用GCC做點什麼? –
爲什麼它是無效的?它需要一個帶初始化列表的構造函數嗎? – user2023370
GCC -pedantic開關看起來很有用。它說,「ISO C++禁止匿名結構」。如果我刪除上面的'const',我會得到同樣的警告。 – user2023370