Windows 已在 test.exe 中触发一个断点。其原因可能是堆被损坏,这也说明 test.exe 中或它所加载的任何 DLL 中有 bug。
首先定义了一个结构体类型
struct genotype
{
char genBit[NVARS+1];
double genValue;
double fitness;
double rfitness;
double cfitness;
};
然后在类中定义了两个genotype指针
genotype* population;/*种群*/
genotype* newpopulation;/*新种群*/
在类的构造函数中new出空间(POPSIZE是传过来的值)
population = new genotype[POPSIZE+1];
newpopulation = new genotype[POPSIZE+1];
其它地方没有使用到newpopulation指针
析构函数中delete这两个指针
delete population;/*位置1*/
population = NULL;
if(newpopulation !=NULL)
{
delete newpopulation;/*位置2*/
}
但是每次运行到delete newpopulation这句话时(位置2处)就显示
“Windows 已在 test.exe 中触发一个断点。其原因可能是堆被损坏,这也说明 test.exe 中或它所加载的任何 DLL 中有 bug。”
如果我把genotype* population;/*种群*/
genotype* newpopulation;/*新种群*/
这两句话换个次序,先定义newpopulation指针的话,析构函数中运行到位置1处就出现上面的错误。
很头痛,bug求解
我用的开发平台式vs2008