Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A special member function that is automatically called when an object is destroyed. Its main job is to release resources (like heap memory) that the object acquired during its lifetime.
class MyClass {
public:
~MyClass() {
// Cleanup code here
cout << "Object destroyed";
}
};The tilde ~ symbol prefix indicates a destructor.
A destructor cannot take any arguments. You can only have ONE destructor per class.
Like constructors, destructors have no return type.
delete is called on a pointer to an object