class A
{
public:
~A()
{
std::cout << "A destroyed" << std::endl;
}
};
class B
{
public:
A a;
~B()
{
std::cout << "B destroyed" << std::endl;
}
};
int main()
{
B b;
b.~B();
}
输出:
B destroyed
A destroyed
B destroyed
A destroyed
有人可以向我解释这里发生了什么吗?我希望输出是
B destroyed
A destroyed
(一次当 ~B() 被调用,一次 ~A() 被调用)。