I have having trouble understanding what a tilde would do for a constructor.
1 2 3 4 5 6 7 8
class MyClass
{
public:
~MyClass();
private:
MyClass();
}
I just need a link or term to search for, or an explanation. I can find nothing on what this is. I have read that that the tilde 'inverses' the bits. So is this an 'inverse constructor'?? or 'Not a Constructor'??
~MyClass is the destructor, which is called when the object either goes out of scope or is explicitly destroyed. Just has "constructor" is often shortened to "ctor", "destructor" is often abbreviated as "dtor".
A class will always have a destructor - if you don't provide one, the compiler generates one for you. While the destructor is implemented by hand for lower-level classes, in higher-level classes it is considered bad if the default compiler-generated destructor is not sufficient.
The destructor must always take 0 parameters. Like the constructor, it has no return type but the return statement can be used to finish it early.