hi, i have this function that allocates memory for a char *temp. wanted to know if there is a way to call the destructor every time i leave the function so that the space is deallocated. Or any other suggestions would do great.
Code:const char* Microwave::status(void) { temp=new char[80]; time(&end);//captures time again difference=difftime(end,starts); if(difference<seconds) { sprintf(temp,"Microwave in use. %.0f seconds left",seconds-difference); return temp; } //if difference is greater than the number of seconds, its off //if seconds is 0 then its off if(difference>seconds || seconds==0) { seconds=0; sprintf(temp,"Microwave not in use"); return temp; } //a default return incase none of the conditions are met return ""; } Microwave::~Microwave() { cout<<"called"; delete[] temp; }



LinkBack URL
About LinkBacks


