P
penny336
dear all,
i am using vc++ 6.0 sp5
i have a class called Address,it allocated some memory space for streetname
and city
i first define it as
Address add = new Address("Madrian","UK");
...
delete add // delete it explicitly
end of program
but my program get error that before the end of program the destructor is
called again and try to delete the street again,
how to prevent action, i have tried to use sizeof (street) or !=null to
check in if loop, but it still can jump and try to delete street again
it is not i want, please give me solution.
here is my destructor
Address::~Address () {
cout << "address destructor is called"<<endl;
if (sizeof(street) >0 )
{
cout <<"Delete Street"<<endl;
delete [] street;
street = NULL;
}
if (city !=NULL)
{
cout <<"Delete city"<<endl;
delete [] city;
city = NULL;
}
}
i am using vc++ 6.0 sp5
i have a class called Address,it allocated some memory space for streetname
and city
i first define it as
Address add = new Address("Madrian","UK");
...
delete add // delete it explicitly
end of program
but my program get error that before the end of program the destructor is
called again and try to delete the street again,
how to prevent action, i have tried to use sizeof (street) or !=null to
check in if loop, but it still can jump and try to delete street again
it is not i want, please give me solution.
here is my destructor
Address::~Address () {
cout << "address destructor is called"<<endl;
if (sizeof(street) >0 )
{
cout <<"Delete Street"<<endl;
delete [] street;
street = NULL;
}
if (city !=NULL)
{
cout <<"Delete city"<<endl;
delete [] city;
city = NULL;
}
}