I want to prevent the user of my class from using it as an automatic variable, so I write code like this:
class A {
private:
~A() = default;
};
int main() {
A a;
}
I expect that the code won't be compiled, but g++ compiles it without error.
However, when I change the code to:
class A {
private:
~A(){}
};
int main() {
A a;
}
Now, g++ gives the error that ~A()
is private, as is my expectation.
What's the difference between a "= default" destructor and an empty destructor?
See Question&Answers more detail:os