How do I overload a destructor?
You can't. There is only one destructor per class in C++.
It does not accept any parameter and cannot be overloaded.
Source. Constructor and Destructor are the special member functions of the class which are created by the C++ compiler or can be defined by the user. Constructor is used to initialize the object of the class while destructor is called by the compiler when the object is destroyed.
After a destructor has been created as a pure virtual object(instance of a class), where the destructor body is provided. This is due to the fact that destructors will not be overridden in derived classes, but will instead be called in reverse order.
You can't. There is only one destructor per class in C++.
What you can do is make a private destructor and then have several public methods which call the destructor in new and interesting ways.
class Foo {
~Foo() { ... }
public:
DestroyFoo(int) { ... };
DestroyFoo(std::string) { ... }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With