Hi.
This is probably really basic stuff, but I'm coming very unstuck with using arrays of chars on the heap.
My class (Tdb_field) only creates them in two places (both class constructors) with the following code - btw, str is a string passed to the constructor, and char* Fdata is the character array I use to store the data.
if(str.length()>0){
Fdata=new char[str.length()+1];
strcpy(Fdata,str.c_str());
}
else
Fdata=0;
In the destructor, I have:
if(Fdata){
if(strlen(Fdata>0)){
delete[]Fdata;
Fdata=0;
}
}
On top of this, I set Fdata to NULL before any of this is reached, and nowhere else in my code do I alter Fdata.
I've tried changing the line in the destructor to "delete Fdata;", but I get the same error.
The only thing that works currently is commenting out the delete, but this is not acceptable for obvious reasons.
I guess I know what the problem is, I just don't know what's causing it - so has anyone any handy hints as to what I might look for?
All help appreciated,
Douglas J Livesey
Common sense is what tells you the world is flat.
This is probably really basic stuff, but I'm coming very unstuck with using arrays of chars on the heap.
My class (Tdb_field) only creates them in two places (both class constructors) with the following code - btw, str is a string passed to the constructor, and char* Fdata is the character array I use to store the data.
if(str.length()>0){
Fdata=new char[str.length()+1];
strcpy(Fdata,str.c_str());
}
else
Fdata=0;
In the destructor, I have:
if(Fdata){
if(strlen(Fdata>0)){
delete[]Fdata;
Fdata=0;
}
}
On top of this, I set Fdata to NULL before any of this is reached, and nowhere else in my code do I alter Fdata.
I've tried changing the line in the destructor to "delete Fdata;", but I get the same error.
The only thing that works currently is commenting out the delete, but this is not acceptable for obvious reasons.
I guess I know what the problem is, I just don't know what's causing it - so has anyone any handy hints as to what I might look for?
All help appreciated,
Douglas J Livesey
Common sense is what tells you the world is flat.