Answer Posted / priya
Using delete this in destructor will lead to recursive loop
which will lead to Stack overflow...so avoid it over
here...however there are few times where your code with
delete this will just work fine..like in the usage of
garbage colletors in C++.Chk the below code...which works
with no issues:
class temp
{
public:
temp(){std::cout<<"Constructor"<<std::endl;}
~temp(){std::cout<<"Destructor"<<std::endl;}
void destroy() {std::cout<<"In class
temp"<<std::endl;delete this;}
};
int main()
{
temp *t = new temp;
t->destroy();
return 0;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is the difference between ++ count and count ++?
What is extern c++?
What is enum class in c++?
What are the effects after calling the delete this operator ?
Is c++ still being used?
What are the differences between malloc() and calloc()?
What are put and get pointers?
What's the most powerful programming language?
What are the 4 types of library?
Can non graphic characters be used and processed in C++?
what is the difference between overloading & overriding? give example.
Why do we use structure in c++?
What is the output of the following program? Why?
Why namespace is used in c++?
There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.