是否有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:条件表达式无效
感谢