Main Page | See live article | Alphabetical index

Destructor

In computer science a destructor is a method called when an instance of a class is deleted, before the memory is deallocated.

Table of contents
1 Example
2 Also see

Example

C++

class Foo
{
   // This is the prototype of the destructor
   ~Foo();
}

Foo::~Foo() {

   // This is the implementation of the destructor
}

int main() {

   Foo* foo = new Foo;

// This is where the destructor is being called delete Foo;

return 0;

}

Also see

Constructor (antonym).