It would be interesting to comment the delete within the destructor, and see what happens:
Code:asset::~asset()
{ //delete [] name; }
Printable View
It would be interesting to comment the delete within the destructor, and see what happens:
Code:asset::~asset()
{ //delete [] name; }
In principle, the compiler should hit an "Unexpected end of file" error. ;) But anyway, that line should be fine, as should something like this:
By the way, what compiler are you using, misplaced?Code:#include <iostream>
int main() {
char* str = NULL;
delete[] str;
std::cout << "Deletion successful." << std::endl;
return 0;
}
>In principle, the compiler should hit an "Unexpected end of file" error.
:o Heh, let me try again:
There's a mystery here which would be nice to solve. I've run it with both Dev-C++ and Borland. Is it the compiler, or some part of the classes Misplaced hasn't posted?Code:asset::~asset()
{
//delete [] name;
}
Well, misplaced, can you run it through a debugger? It sure would be nice to know exactly what line in what function call that the thing crashes on (one of the destructors I assume).
you solved the mystery.......Quote:
Originally Posted by swoopy
delete [] name
was causing it all along.......
any ideas?
Invalid pointer value AKA seg fault, or deconstructed twice (has happened to me). To make a solid deconstructor do this:
Code:asset::~asset(){
if(name)
delete [] name;
name=0;
}
//And had this to the asset constructor
asset::asset() : name(0) /*other constructors*/{
// do the stuff you want
}
>any ideas?
A bug in your compiler?
Try these two things, and see if either or both work.
(1)
(2)Code:asset::~asset()
{
cout << "Asset ~asset()" << endl;
if (name != NULL)
delete [] name;
}
Code:asset::~asset()
{
cout << "Asset ~asset()" << endl;
delete name;
}
Can you post the whole thing in a zip? I'd like to run it through a debugger.