POD members release moment in Destructor

I'm curious when are POD member variables released when calling a destructor.

1
2
3
4
5
6
7
8
class L2
{
public:
	int eCount;
        int GetCount() {return eCount;}
        ~L2()
        { std::cout << GetCount(); }
}


Are the POD members released at the beginning of the destructor call or at the end of it ? Do I risk printing garbage?

If they were released at the beginning, then writing something like that :
1
2
3
        ~L2()
        {  int a = 40;
           std::cout << GetCount(); }


would mean that I risk "a" will be pun on the released space of eCount and thus GetCount would print value of "a" - thats mostly what concerns me.
They will be "released" after. You can always use data members of the class in the destructor, no matter if they are POD or not.

When an object is destroyed:

1) Your destructor body is run
2) Destructors are run for any member objects of the class (like if you have any strings/vectors/etc)
3) Destructor bodies for the parent class(es) are run
4) Destructors for the parent(s) members are run
5) Once all destructors are run, memory for the object is released.


So:
Are the POD members released at the beginning of the destructor call or at the end of it ?


The end. Having a destructor would be useless if you couldn't use your members in it.

Do I risk printing garbage?


No.
Topic archived. No new replies allowed.