1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
class MyClass {
public:
MyClass() {
std::cout << "Constructor called." << std::endl;
}
~MyClass() {
std::cout << "Destructor called." << std::endl;
}
};
int main() {
MyClass* ptr = new MyClass(); // Dynamically allocate memory for a MyClass object
delete ptr; // Deallocate the memory and call the destructor
return 0;
}
Back to delete