I would want to know if it is useful to put a destructor in constant? E.g.:
class example { public : example(int params); const ~example(); //Here }
I would want to know if it is useful to put a destructor in constant? E.g.:
class example { public : example(int params); const ~example(); //Here }
From a conceptual standpoint, this does not make any sense. const
functions have no side-effects. Thus, they need to return something. As the destructor does not return anything, this function would be useless.
(Similar to a const void function by the way)
As noted in the comments, you could still modify mutable
data in a const
.
It's not useful, because it's not possible:
error: qualifiers are not allowed on destructor declaration
It is not useful, and would typically trigger a warning from the compiler - usually to the effect of the qualifier being ignored.
A const
qualifier on the return from a function is mostly only useful for functions that return a pointer or reference (e.g. to indicate that the returned reference is to an object that should not logically be changed). A destructor does not return anything so there is nothing for the const
to qualify.
Making the destructor itself const
(i.e. ~example() const
) will be rejected by the compiler. That is appropriate since a destructor generally changes state of the object (causes it to no longer logically exist)