In the following code the destructor for a
is called twice, and the first call seems to be ignored:
struct A1
{
int A;
A1(int a=0) : A(a) { std::cout << "ctor: " << A << "\n"; std::cout.flush(); }
~A1() { std::cout << "dtor: " << A << "\n"; std::cout.flush(); }
};
int main()
{
A1 a(1), *pa=new A1(2), *pb=new A1(3);
a.~A1();
pa->~A1();
delete pb;
std::cout << "'destructed' a.A = " << a.A << "\n"; std::cout.flush();
return 0;
}
Output:
ctor: 1
ctor: 2
ctor: 3
dtor: 1
dtor: 2
dtor: 3
'destructed' a.A = 1
dtor: 1
What is happening here?