views:

201

answers:

2

How do you specify a method to be a destructor rather than a constructor in C++? This confuses me very much. I can't tell the difference between the two.

+12  A: 

Here's an example:

MyClass::MyClass()   // Constructor 
MyClass::~MyClass()  // Destructor

Note the "~" in front of the destructor.

Soo Wei Tan
~ is the not operator (logical), funny C++ designers
CrazyJugglerDrummer
Nitpick: ~ is the *bitwise* not operator, not the *logical* not operator.
j_random_hacker
+4  A: 
davidivins
+1, sound advice.
j_random_hacker