有什么原因会导致delete[] xxx;出错
我只知道xxx是空指针,或是野指针时会出错,还有别的吗?
struct stCell{
unsigned Pic:6;
unsigned Num:14;
unsigned res:4;
};
stCell* m_CellLayerOne = new stCell[n]; //n是运行时从文件中读的
中间有好多代码...
最后我这样
if( m_CellLayerOne )
{
delete[] m_CellLayerOne; //出错
m_CellLayerOne = NULL;
}
这时有什么原因会使delete[] 出错??
上个贴说的不清,我再从说
[解决办法]
因为我的文件中中存了Pic和Num(加起来就是20)这两个,没有放res的值,res只是保留用的,所以读20,不能从文件中读20个放到stCell的前20个单元中吗?
-------------------------------------------------
楼主没有试试上面的程序么?
本来想让楼主自己动手,加深点印象,现在只好直接说了:
所谓(加起来就是20):是20 bits,可是楼主读了是20bytes.