[C++] Heap corruption detected! 05-24-2011, 09:43 AM
#1
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:
It seems correct to me...
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;
};