![]() |
|
[C++] Heap corruption detected! - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C) +--- Thread: [C++] Heap corruption detected! (/Thread-C-Heap-corruption-detected) |
[C++] Heap corruption detected! - Falcøn - 05-24-2011 Hi I got this error when I make a delete in a constructor and I can't figure out whyT_T This is my class: Code: lass DataContainer{
public:
DataContainer(){
data = NULL;
valid = false;
}
DataContainer(const char* data1){
data = new char[strlen(data1)];
strcpy(data,data1);
valid = true;
}
bool isValid();
const char* getData();
void setData(char* data1);
~DataContainer(){
if(valid){
delete [] data; //this is the instruction
}
}
private:
bool valid;
char* data;
}; |