my question is basically why shall we use destructor in c++?

To do cleanup such as deallocate memory before the class is destroyed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.