尊敬的C++大师们,我来请教你们。请用标准语言告诉我,C++是否保证以下程序:
#include <iostream>
using namespace std;
struct A
{
A() { cout << "A::A" << endl; }
~A() { cout << "A::~" << endl; }
};
struct B
{
B() { cout << "B::B" << endl; }
~B() { cout << "B::~" << endl; }
};
struct C
{
C() { cout << "C::C" << endl; }
~C() { cout << "C::~" << endl; }
};
struct Aggregate
{
A a;
B b;
C c;
};
int main()
{
Aggregate a;
return 0;
}
将始终产生
A::A
B::B
C::C
C::~
B::~
A::~
换句话说,成员的初始化是否保证按声明顺序进行,销毁是否按相反顺序进行?