Professional Documents
Culture Documents
Assigment #3 (233308, 233307)
Assigment #3 (233308, 233307)
Basic Syntax
class ClassName {
public:
~ClassName() {
// Destructor code
cout<<”This is destructor.”<<endl;
}
};
Properties of C++ Destructor
Output
Example explanation: This destructor will print the message
"Destructor called!" when it is invoked, which happens
automatically when the object obj of class OOP goes out of scope.
Although this example does not involve resource allocation, in a
more complex class, the destructor would handle the cleanup of
resources.
The destructor ensures that any final actions are taken before the
object is completely removed from memory.
Conclusion