﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-021742-随笔分类-C++</title><link>http://www.cppblog.com/021742/category/3876.html</link><description>心要存高远，行才有信心！

</description><language>zh-cn</language><lastBuildDate>Sat, 24 May 2008 01:06:40 GMT</lastBuildDate><pubDate>Sat, 24 May 2008 01:06:40 GMT</pubDate><ttl>60</ttl><item><title>[讨论]临时对象有地址么？</title><link>http://www.cppblog.com/021742/archive/2006/02/12/3219.html</link><dc:creator>猪头饼</dc:creator><author>猪头饼</author><pubDate>Sun, 12 Feb 2006 14:12:00 GMT</pubDate><guid>http://www.cppblog.com/021742/archive/2006/02/12/3219.html</guid><wfw:comment>http://www.cppblog.com/021742/comments/3219.html</wfw:comment><comments>http://www.cppblog.com/021742/archive/2006/02/12/3219.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/021742/comments/commentRss/3219.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/021742/services/trackbacks/3219.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> A<br /><img id="Codehighlighter1_8_221_Open_Image" onclick="this.style.display='none'; Codehighlighter1_8_221_Open_Text.style.display='none'; Codehighlighter1_8_221_Closed_Image.style.display='inline'; Codehighlighter1_8_221_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_8_221_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_8_221_Closed_Text.style.display='none'; Codehighlighter1_8_221_Open_Image.style.display='inline'; Codehighlighter1_8_221_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_8_221_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_8_221_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img id="Codehighlighter1_58_59_Open_Image" onclick="this.style.display='none'; Codehighlighter1_58_59_Open_Text.style.display='none'; Codehighlighter1_58_59_Closed_Image.style.display='inline'; Codehighlighter1_58_59_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_58_59_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_58_59_Closed_Text.style.display='none'; Codehighlighter1_58_59_Open_Image.style.display='inline'; Codehighlighter1_58_59_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    A(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> ii):i(ii)</span>
						<span id="Codehighlighter1_58_59_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_58_59_Open_Text">
								<span style="COLOR: #000000">{}</span>
						</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">cout&lt;&lt;i&lt;&lt;"  A() "&lt;&lt;endl;</span>
						<span style="COLOR: #008000">
								<br />
								<img id="Codehighlighter1_99_100_Open_Image" onclick="this.style.display='none'; Codehighlighter1_99_100_Open_Text.style.display='none'; Codehighlighter1_99_100_Closed_Image.style.display='inline'; Codehighlighter1_99_100_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_99_100_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_99_100_Closed_Text.style.display='none'; Codehighlighter1_99_100_Open_Image.style.display='inline'; Codehighlighter1_99_100_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    A():i(</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)</span>
						<span id="Codehighlighter1_99_100_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_99_100_Open_Text">
								<span style="COLOR: #000000">{}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img id="Codehighlighter1_111_139_Open_Image" onclick="this.style.display='none'; Codehighlighter1_111_139_Open_Text.style.display='none'; Codehighlighter1_111_139_Closed_Image.style.display='inline'; Codehighlighter1_111_139_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_111_139_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_111_139_Closed_Text.style.display='none'; Codehighlighter1_111_139_Open_Image.style.display='inline'; Codehighlighter1_111_139_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #000000">~</span>
						<span style="COLOR: #000000">A()</span>
						<span id="Codehighlighter1_111_139_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_111_139_Open_Text">
								<span style="COLOR: #000000">{cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">~A(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">i</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">) </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> A </span>
						<span style="COLOR: #0000ff">operator</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> A </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">r) </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_187_219_Open_Image" onclick="this.style.display='none'; Codehighlighter1_187_219_Open_Text.style.display='none'; Codehighlighter1_187_219_Closed_Image.style.display='inline'; Codehighlighter1_187_219_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_187_219_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_187_219_Closed_Text.style.display='none'; Codehighlighter1_187_219_Open_Image.style.display='inline'; Codehighlighter1_187_219_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_187_219_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_187_219_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> A(i</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">r.i);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_236_425_Open_Image" onclick="this.style.display='none'; Codehighlighter1_236_425_Open_Text.style.display='none'; Codehighlighter1_236_425_Closed_Image.style.display='inline'; Codehighlighter1_236_425_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_236_425_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_236_425_Closed_Text.style.display='none'; Codehighlighter1_236_425_Open_Image.style.display='inline'; Codehighlighter1_236_425_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_236_425_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_236_425_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">10</span>
						<span style="COLOR: #000000">,j</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">20</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">cout&lt;&lt;&amp;(i+j)&lt;&lt;endl;          </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">这里为什么会出错呢？</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    A a1(</span>
						<span style="COLOR: #000000">10</span>
						<span style="COLOR: #000000">),a2(</span>
						<span style="COLOR: #000000">20</span>
						<span style="COLOR: #000000">),a3(</span>
						<span style="COLOR: #000000">30</span>
						<span style="COLOR: #000000">),a4(</span>
						<span style="COLOR: #000000">40</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;&amp;</span>
						<span style="COLOR: #000000">(a1</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">a2)</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;       </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">这里就应该是临时变量的地址了吧</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<p>
				<br />
				<br />既然这样可以运行，那为什么内置的类型如：int float之类的不能取临时对象的值呢？<br />我重载的+号运算符应该没有写错吧、、<br />请大家指教。。谢谢我还只是一个初学者</p>
<img src ="http://www.cppblog.com/021742/aggbug/3219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/021742/" target="_blank">猪头饼</a> 2006-02-12 22:12 <a href="http://www.cppblog.com/021742/archive/2006/02/12/3219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>