引用 临时对象 生命期 引用和对象之间到底是什么关系? 有代码演示. 多谢

引用 临时对象 生命期 引用和对象之间到底是什么关系? 有代码演示. 谢谢
class   Ctemp
{
public:
int   k;
public:
Ctemp(int   ik   =   29)
{
k   =   ik;
//cout < <k < <endl;
}

};
int   _tmain(int   argc,   _TCHAR*   argv[])
{  
const   int   &iref   =   30;
        cout < <iref < <endl;
        cout < <iref < <endl;
const   Ctemp   &   t   =   Ctemp(29);
cout < <t.k < <endl;


Ctemp   *pt   =   new   Ctemp(19);
const   Ctemp   &reftem   =   *pt;
cout < <reftem.k < <endl;
delete   pt;
cout < <reftem.k < <endl;
cout < <t.k < <endl;
return   0;
}
输出结果:
30
30
29
19
-572662307
29
Press   any   key   to   continue

哪个给解释下   :为什么是:-572662307   而不是19,如果说引用的对象释放了
所以是-572662307(释放掉内存中的数据),那为什么引用临时对象那个输出还是
29。临时对象在const   Ctemp   &   t   =   Ctemp(29);之后就会调用析构函数销毁改对象啊。有证据如下:
临时匿名对象的生存期被定在一句语句的结束。也就是到了下一行语句之前,临时匿名对象被销毁。关于这个生存期的问题标准委员会有过长时间的争论,最终确定这个方案。理由差不多是:有一个方案比没有这个方案强。(来自别人发的贴子中   longshanks(longshanks)   的回答。帖子:http://community.****.net/Expert/topic/5494/5494160.xml?temp=.6641352)

哪个给解释下

  谢谢

------解决方案--------------------
const Ctemp & t = Ctemp(29);
你问这个啊,
只能怪你看书不仔细了
C++规定,临时对象如果绑定给一个const引用的话,这个临时对象的生存期将加长到和那个引用相同。
建议你找 <C++ Primer> 认真学学。
------解决方案--------------------
const Ctemp & t = Ctemp(29); // 这里创建一个匿名对象

const Ctemp &reftem = *pt; // 这里为同一物

delete pt; // 释放自然没有了,不错仅仅是内存回收

cout < <t.k < <endl; // t和reftem有什么关系吗
------解决方案--------------------
很正确啊!
Ctemp *pt = new Ctemp(19);
const Ctemp &reftem = *pt;
reftem 仅仅是 *pt 的别名!pt都delete掉了,reftem自然就不存在指向垃圾了
至于t,已经是对象Ctemp(29),加不加&仅仅是通过构造函数还是复制构造函数生成而已。他的生命期与main函数相同,没什么可奇怪的,倒是taodm的解释看上去怪怪的,看来还要taodm自己来解释了。
------解决方案--------------------
相信指针释放掉,之后输出随机数这块楼主已经明白了

不明白的是为什么那个临时对象没有被释放掉而使常引用成为随机数。

等待详解
------解决方案--------------------
匿名对象和临时变量就是同义词。
------解决方案--------------------
是临时对象生命期延长的问题。
taodm就是牛,

我翻了书,在c++标准白皮书书(2003SE),第十二章第二节第5条上P192上有详细例子
const C& cr = C(16)+C(23);

the expression C(16)+C(23) creates three temporaries

A first temporary T1 to hold the result of the
expression C(16), a second temporary T2 to hold the result of the expression C(23), and a third temporary T3 to hold the result of the addition of these two expressions. The temporary T3 is then bound to the
reference cr
The temporaries T1 and T2 are bound to
the reference parameters of operator+; these temporaries are destroyed at the end of the full expression
containing the call to operator+. The temporary T3 bound to the reference cr is destroyed at the end of cr 's lifetim
------解决方案--------------------
to:taodm
匿名对象和临时变量就是同义词。
-------------------------
这点我不能认同,我认为匿名对象与临时变量相似但是两回事。临时变量是指中间变量,一种仅在其调度区域有定义的一种变量,对外可能存在调用形式也可能并不存在,比方说: