|
|
使在delete[] m_CellLayerOne;时报错
**********************************************
struct stCell{
unsigned Pic:6;
unsigned Num:14;
unsigned res:4;
};
***********************************************
在给m_CellLayerOne里面赋值前会把它清成统一的数:
//n=336;
for( int i=0; i<n; i++ )
{
m_CellLayerOne.Pic = 63;
m_CellLayerOne.Num = 2047;
}
***********************************************
原本我只分配了336个stCell的空间,m_CellLayerOne应到335,但在delete[]时,m_CellLayerOne[336]中也有值,太郁闷了!!!!!!!!!!!!但是怎么也看不明白为什么,我不知道为什么会多出那么一个
m_CellLayerOn[336]!!!:
n = 336;
stCell temp[400]; //记录用的
if( m_CellLayerOne )
for( int j=0; j<400; j++ )
{
temp[j].Pic = m_CellLayerOne[j].Pic;
temp[j].Num = m_CellLayerOne[j].Num;
}
//层信息
for( int i=0; i<n; i++ )
{
//这里最是奇怪的,我单步执行时,一下一下F10时,i=335,temp[336]中
//正常(不是我一开始给我的初值)!!但一当我设断点一下子到i =335 时,temp[336]就不正常了(是我一开始的初值)
if( i==335)
{
for( int j=0; j<400; j++ )
{
temp[j].Pic = m_CellLayerOne[j].Pic;
temp[j].Num = m_CellLayerOne[j].Num;
}
}
fread( &m_CellLayerOne, 20, 1, fp );
fread( &m_CellLayerTwo, 20, 1, fp );
fread( &m_CellLayerThree, 20, 1, fp );
fread( &m_EventLayer, 7, 1, fp );
}
if( m_CellLayerOne )
for( int j=0; j<400; j++ )
{
temp[j].Pic = m_CellLayerOne[j].Pic;
temp[j].Num = m_CellLayerOne[j].Num;
}
//执行上面代码前temp[336].Pic = 61; temp[336].Num = 14327;
//执行过后temp[336].Pic = 63; temp[336].Num = 2047;
|
|