Should destructior be declared/implemented in pointerless class?
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:
- Resource management(Memory managemnt, FIle handling),
- Logging,
- Close network connections,
- In short custom functionality which needs to execute each time a object is destroyed
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 delete
on a Base class pointer pointing to a derived class object then you need to provide a destructor and mark it as virtual
in Base class, failure to do so will result in Undefined Behavior.
Is there any advantage of having/not having it?
None, since the compiler does the same there is no need to do the extra typing.