Should destructior be declared/implemented in pointerless class?
Is there any advantage of having/not having it ?
What I men is:
class Point
{
public:
int X, Y;
Point(int x, int y);
//~Point(void); //should I uncoment it and implement empty destructor ?
}
No need[conditions apply]. the compiler will generate one for you.
You should provide one only if you want to perform something specific, which the compiler will not.
For example:
In general the thumb rule is:
“If you need to provide a copy constructor or a copy assignment operator then you most probably also need to provide your own destructor.”
Popularly, this rule is known as the Rule of Three.
[conditions apply] If your class is meant to act as an Base class for Inheritance and your implementation will require calling
deleteon a Base class pointer pointing to a derived class object then you need to provide a destructor and mark it asvirtualin Base class, failure to do so will result in Undefined Behavior.None, since the compiler does the same there is no need to do the extra typing.