mercredi 21 janvier 2015

Error : Heap block at X modified

I was trying to use destructors for a struct. However, the compiler reported errors that Heap block at 006651F8 modified at 00665229 past requested size of 29 gift1.exe has triggered a breakpoint.



#include "stdafx.h"

struct Node{
char *name;
int age;

Node(char *n = 0, int a = 0){
this->name = _strdup(n);
age = a;
}

~Node(){
if (this->name != 0)
delete[] this->name;
}
};

int _tmain(int argc, _TCHAR* argv[])
{

Node node1("Andy", 20);
return 0;
}


May I know where went wrong?


Does it matter if I use nameinstead of this->name ?


Aucun commentaire:

Enregistrer un commentaire