Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with deconstructors

Status
Not open for further replies.

strack

Programmer
Jan 27, 2001
3
0
0
US
I have a small class that I'd like to be able to write data to. However, whenever I invoke the write function, I receive an error upon deallocation. I know I'm doing something wrong with memory management (because it works fine for my character arrays), but I can't seem to figure out what. I would greatly appreciate any help anyone can give me. Here's the code I'm having problems with:


// set a new date
void Model::setDate(const int newDate)
{ date=newDate; }

// deconstructor
Model::~Model()
{ delete &date; }

 
It should be
delete date
and not
delete &date
- Karthika
 
EEK!!!!... it looks like you dont need a delete at all! If you declare date as

int date in your header file dont call delete on it. It will be deleted upon distruction. Only delete it if you new it.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top