Consider the following code:
#include <iostream>
class Test
{
public:
constexpr Test(const int x) : _x(x) {}
constexpr int get() const {return _x;}
~Test() {} // HERE
protected:
const int _x;
};
int main()
{
static constexpr Test test(5);
return 0;
}
If I remove the line HERE
the code compiles well, but if I define an empty destructor, it results to a compilation error saying that Test
is non-literal.
Why and what is the difference between an empty destructor and no destructor at all ?
EDIT: Another related question : if empty and literal destructors are different how to define a protected literal destructor ?