是否有C++的方式在聯盟/類/結構作爲一個默認設置的屬性?我使用Visual Studio。 這個想法是能夠訪問它們而不必引用它。喜歡的東西:C++默認類屬性
typedef uint64_t tBitboard;
union Bitboard {
tBitboard b; //modifier somewhere in this line to set as default
uint8_t by[8];
};
Bitboard Board;
然後,我要訪問:
Board=100;
這使100在Board.b 或者
Board.by[3]=32;
所以把32的字節3陣列。我認爲這是不可能的,但可能有人知道一種方式。 謝謝!
不錯的解決方案!
我試圖使用這一個: 聯合Bitboard { tBitboard b; std :: uint8_t [8];
Bitboard(tBitboard value = 0) { b = value; }
Bitboard& operator = (tBitboard value) { b = value; return *this; }
};
但在這一行有錯誤:
if (someBitboard)
錯誤166錯誤C2451:條件表達式無效
感謝