C++: What does the class destructor do?
Suppose we have an object "myObject", and has several members as follows:
int a;
float b;
yourClass yourObject;
void hisMethod();
From what I read, the memory allocated to "myObject" is like this order.
Once the destructor is called, what happened?
After the destructor is called, before the object is destroyed, from what I read, I can still access (a) the object "myObject". (b) the member yourObject (c) the member hisMethod()
Can I still access its members? It is undefined behavior?
Many C++ books do not talk more details on it. Where can I find more details on it? Because details can help me understand many C++ rules like "not manually call destructor unless after placement new".
[Update 1] I raise my question because I saw the post: What does empty destructor do? The poster gives an example as below:
#include <iostream>
#include <set>
class a
{
public:
std::set <int> myset;
};
int main()
{
a object;
object.myset.insert(55);
object.~a();
object.myset.insert(20);
std::cout << object.myset.size();
}
The poster get: "* glibc detected * /.app: double free or corruption (fasttop):" and then "ABORT".
This means:
object.myset.insert(20);
doesn't raise error, which means the object still exists after destructor manually called. Its class member can still be called!
Double calling of deconstructor gives error.
[Update 1] I run the code in QT Creator, and when run to object.myset.insert(20);
it raise error:
read access violation at: 0x0, flags=0x0.