给定以下代码:
class foo
{
};
class bar: public foo
{
public:
~bar() { printf("~bar()\n"); }
};
class zab: public foo
{
public:
~zab() { printf("~zab()\n"); }
};
struct foo_holder
{
const foo &f;
};
int main()
{
foo_holder holder[]= { {bar()}, {zab()} };
printf("done!\n");
return 0;
}
输出是:
~bar()
~zab()
done!
C++0x 有一个子句规定这可以在用作新的初始化程序时创建悬空引用,但它没有说明(至少我找不到任何东西)关于 const 临时引用的聚合初始化。
那么这是未指定的行为吗?