What is '~' for?

Write your question here.

1
2
3
WorldCup::~WorldCup() {
// empty...
}



Sometimes I can see this kind of constructor
but I don't see why '~' is needed and what is it for.
It's not a constructor.

It's the destructor. It's the function that gets called when the object is destroyed, either by going out of scope or by having delete called on it.

It's for doing anything that needs doing when the object lifetime ends. For example, releasing resources.

You should never call it.
Last edited on
It's called a destructor. It's mainly used for deallocation of memory space if you have any pointer-type variables in your class.

http://lmgtfy.com/?q=c%2B%2B+destructor
Thank you for the answers!:)
Topic archived. No new replies allowed.