考慮此代碼時,2013例外:VS使用C++ 11個不受限制工會
struct TNumeric {
bool Negative;
wstring Integral;
wstring Fraction;
};
union TValue {
// The unnamed structs are needed because otherwise the compiler does not accept it...
bool Bit;
struct{ TNumeric Numeric; };
struct{ wstring Text; };
};
TNumeric Numeric;
TNumeric &rNumeric{ Numeric };
rNumeric.Integral = L"";
rNumeric.Integral.push_back(L'X'); //OK, no problem
TValue Value;
TValue &rValue{ Value };
rValue.Text = L"";
rValue.Text.push_back(L'X'); //OK, no problem
rValue.Numeric.Integral = L"";
rValue.Numeric.Integral.push_back(L'X'); // Exception
在釋放模式是沒有問題的。在調試模式下運行時,xutility:Access violation reading location 0x0000005C
中_Iterator_base12類的方法_Adopt中的最後一條語句存在異常。
在_Adopt代碼僅在_ITERATOR_DEBUG_LEVEL == 2
時運行。我試着用
#define _ITERATOR_DEBUG_LEVEL 1
在我的主要程序添加,但它仍然定義爲2 有沒有一種方法來禁用檢查?
另外'的boost :: variant'將採取新的佈局和位置刪除構建/破壞工會元素的照顧。 – AndyG
好的,很清楚!由於空間不是一個至關重要的問題,所以我只會讓聯合體成爲結構體。 –