Hey all check this out:
struct A
{
int val = 0;
A() { printf( "Construct A [%d]", val ); }
~A() { printf( "Destruct A [%d]", val ); }
};
int main()
{
A a;
a.val = 500;
a = A();
printf( "Finally %d", a.val );
a.val = 300;
return 0;
}
Produces output:
Construct A [0]
Construct A [0]
Destruct A [0]
Finally 0
Destruct A [300]
What the!? Why am I not getting Destruct A [500]?! Memory leaks if I would have some pointers in A cuz its destructor is never called!? I want to see something like this:
Construct A [0]
[color=red]Destruct A [500]
Construct A [0]
Destruct A [0]
Finally 0
Destruct A [300]
What am I doing wrong? Hellup