I heard that empty destructor doesn’t do anything and calling it doesn’t remove the object.
But in the code:
#include <iostream>
#include <set>
class a
{
public:
~a()
{}
std::set <int> myset;
};
int main()
{
a object;
object.myset.insert(55);
object.~a();
object.myset.insert(20);
std::cout << object.myset.size();
}
I get:
“* glibc detected * /.app: double free or corruption (fasttop):” and then “ABORT”.
If it matters I have c++11 flag enabled. So what does empty constructor actually do? It does something and I read it doesn’t.
Your destructor may look empty, but it’s actually destructing the member variables. In this case, it’s destructing
myset, so the subsequentinsert(20)is crashing.If your class had no non-POD member variables then the empty destructor would truly do nothing.