亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 009.htm

?? 21天內快速掌握c++語言
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>-->Learn C++ in 21 Days-->Day 9</TITLE>
<META NAME="888" CONTENT=" Learn C++ in 21 Days Day 9">
<META NAME="888" CONTENT=" - Learn C++ in 21 Days - Day 9">

<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋體"}
.tt2 {font: 12pt/15pt "宋體"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<p align="center"><script src="../../../1.js"></script> </p>
<TD CLASS="tt3" VALIGN="top" width="8%"  bgcolor="#ffffff"><strong><A HREF="010.htm"><FONT style="FONT-SIZE: 9pt">后一頁</font></A><BR>
<A HREF="008.htm"><FONT style="FONT-SIZE: 9pt">前一頁</font></A><BR>

<A HREF="index.html"><FONT style="FONT-SIZE: 9pt">回目錄</font></A><BR>
 
<TD class="tt2" bgcolor="#ffffff" width="100%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷體_GB2312">Day 9</FONT></B></center>
 
	<LI><A HREF="#Heading1">Day 9</A>
	<UL>
		<LI><A HREF="#Heading2">References</A>
		<UL>
			<LI><A HREF="#Heading3">What Is a Reference?</A>
			<LI><A HREF="#Heading4">Listing 9.1. Creating and using references.</A>
			<LI><A HREF="#Heading5">Using the Address of Operator &amp; on References</A>
			<LI><A HREF="#Heading6">Listing 9.2. Taking the address of a reference</A>
			<LI><A HREF="#Heading8">Listing 9.3. Assigning to a reference</A>
			<LI><A HREF="#Heading10">What Can Be Referenced?</A>
			<LI><A HREF="#Heading11">Listing 9.4. References to objects</A>
			<LI><A HREF="#Heading13">References</A>
			<LI><A HREF="#Heading14">Null Pointers and Null References</A>
			<LI><A HREF="#Heading15">Passing Function Arguments by Reference</A>
			<LI><A HREF="#Heading16">Listing 9.5. Demonstrating passing by value</A>
			<UL>
				<LI><A HREF="#Heading18">Making swap() Work with Pointers</A>
			</UL>
			<LI><A HREF="#Heading19">Listing 9.6. Passing by reference using pointers</A>
			<UL>
				<LI><A HREF="#Heading21">Implementing swap() with References</A>
			</UL>
			<LI><A HREF="#Heading22">Listing 9.7. swap() rewritten with references</A>
			<LI><A HREF="#Heading24">Understanding Function Headers and Prototypes</A>
			<LI><A HREF="#Heading25">Returning Multiple Values</A>
			<LI><A HREF="#Heading26">Listing 9.8. Returning values with pointers</A>
			<UL>
				<LI><A HREF="#Heading28">Returning Values by Reference</A>
			</UL>
			<LI><A HREF="#Heading29">Listing 9.9.</A>
			<LI><A HREF="#Heading30">Listing 9.8 rewritten using references.</A>
			<LI><A HREF="#Heading31">Passing by Reference for Efficiency</A>
			<LI><A HREF="#Heading32">Listing 9.10. Passing objects by reference</A>
			<UL>
				<LI><A HREF="#Heading34">Passing a const Pointer</A>
			</UL>
			<LI><A HREF="#Heading35">Listing 9.11. Passing const pointers</A>
			<UL>
				<LI><A HREF="#Heading37">References as an Alternative</A>
			</UL>
			<LI><A HREF="#Heading38">Listing 9.12. Passing references to objects</A>
			<LI><A HREF="#Heading40">const References</A>
			<LI><A HREF="#Heading41">When to Use References and When to Use Pointers</A>
			<LI><A HREF="#Heading42">Mixing References and Pointers</A>
			<LI><A HREF="#Heading43">Dont Return a Reference to an Object that Isnt in Scope!</A>
			<LI><A HREF="#Heading44">Listing 9.13. Returning a reference to a non-existent object</A>
			<LI><A HREF="#Heading46">Returning a Reference to an Object on the Hea</A>
			<LI><A HREF="#Heading48">Listing 9.14. Memory leaks</A>
			<LI><A HREF="#Heading50">Pointer, Pointer, Who Has the Pointer?</A>
			<LI><A HREF="#Heading51">Summary</A>
			<LI><A HREF="#Heading52">Q&amp;A</A>
			<LI><A HREF="#Heading53">Workshop</A>
			<UL>
				<LI><A HREF="#Heading54">Quiz</A>
				<LI><A HREF="#Heading55">Exercises</A>
			</UL>
		</UL>
	</UL>
</UL>
<BR>
<P>
<HR>
<BR>
<BR>
<H2 ALIGN="CENTER"><A NAME="Heading1"></A><FONT COLOR="#000077">Day 9</FONT></H2>
<BR>
<H2 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">References</FONT></H2>
<P>Yesterday you learned how to use pointers to manipulate objects on the free store
and how to refer to those objects indirectly. References, the topic of today's chapter,
give you almost all the power of pointers but with a much easier syntax. Today you
learn the following
<BR>
<UL>
	<LI>What references are.
	<P>
	<LI>How references differ from pointers.
	<P>
	<LI>How to create references and use them.
	<P>
	<LI>What the limitations of references are.
	<P>
	<LI>How to pass values and objects into and out of functions by reference.
</UL>
<BR>
<H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">What Is a Reference?</FONT></H3>
<P>A reference is an alias; when you create a reference, you initialize it with the
name of another object, the target. From that moment on, the reference acts as an
alternative name for the target, and anything you do to the reference is really done
to the target.</P>
<P>You create a reference by writing the type of the target object, followed by the
reference operator (<TT>&amp;</TT>), followed by the name of the reference. References
can use any legal variable name, but for this book we'll prefix all reference names
with &quot;r.&quot; Thus, if you have an integer variable named <TT>someInt</TT>,
you can make a reference to that variable by writing the following:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">int &amp;rSomeRef = someInt;
</FONT></PRE>
<P>This is read as &quot;<TT>rSomeRef</TT> is a reference to an integer that is initialized
to refer to <TT>someInt</TT>.&quot; Listing 9.1 shows how references are created
and used.
<BR>
<BR>
<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><FONT COLOR="#0000AA"><B> </B></FONT>Note
	that the reference operator (<TT>&amp;</TT>) is the same symbol as the one used for
	the address of the operator. These are not the same operators, however, though clearly
	they are related.
<HR>
<BR>
<BR>
</BLOCKQUOTE>
<BR>
<P><A NAME="Heading4"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 9.1. Creating
and using references.</B></FONT>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">
1:    //Listing 9.1
2:    // Demonstrating the use of References
3:
4:    #include &lt;iostream.h&gt;
5:
6:    int main()
7:    {
8:         int  intOne;
9:         int &amp;rSomeRef = intOne;
10:
11:        intOne = 5;
12:        cout &lt;&lt; &quot;intOne: &quot; &lt;&lt; intOne &lt;&lt; endl;
13:        cout &lt;&lt; &quot;rSomeRef: &quot; &lt;&lt; rSomeRef &lt;&lt; endl;
14:
15:        rSomeRef = 7;
16:        cout &lt;&lt; &quot;intOne: &quot; &lt;&lt; intOne &lt;&lt; endl;
17:        cout &lt;&lt; &quot;rSomeRef: &quot; &lt;&lt; rSomeRef &lt;&lt; endl;
18:   return 0;
<TT>19: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: intOne: 5
rSomeRef: 5
intOne: 7
rSomeRef: 7
</FONT></PRE>
<P><FONT COLOR="#000077"><TT><B>Anaylsis: </B></TT></FONT>On line 8, a local <TT>int</TT>
variable, <TT>intOne</TT>, is declared. On line 9, a reference to an <TT>int</TT>,
<TT>rSomeRef</TT>, is declared and initialized to refer to <TT>intOne</TT>. If you
declare a reference, but don't initialize it, you will get a compile-time error.
References must be initialized.<BR>
On line 11, <TT>intOne</TT> is assigned the value <TT>5</TT>. On lines 12 and 13,
the values in <TT>intOne</TT> and <TT>rSomeRef</TT> are printed, and are, of course,
the same.</P>
<P>On line 15, <TT>7</TT> is assigned to <TT>rSomeRef</TT>. Since this is a reference,
it is an alias for <TT>intOne</TT>, and thus the <TT>7</TT> is really assigned to
<TT>intOne</TT>, as is shown by the printouts on lines 16 and 17.
<H3 ALIGN="CENTER"><A NAME="Heading5"></A><FONT COLOR="#000077">Using the Address
of Operator &amp; on References</FONT></H3>
<P>If you ask a reference for its address, it returns the address of its target.
That is the nature of references. They are aliases for the target. Listing 9.2 demonstrates
this.</P>
<BR>
<P><A NAME="Heading6"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 9.2. Taking the
address of a reference</B></FONT><FONT SIZE="2" COLOR="#000077"><B>.</B></FONT>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">
1:    //Listing 9.2
2:    // Demonstrating the use of References
3:
4:    #include &lt;iostream.h&gt;
5:
6:    int main()
7:    {
8:        int  intOne;
9:        int &amp;rSomeRef = intOne;
10:
11:       intOne = 5;
12:       cout &lt;&lt; &quot;intOne: &quot; &lt;&lt; intOne &lt;&lt; endl;
13:       cout &lt;&lt; &quot;rSomeRef: &quot; &lt;&lt; rSomeRef &lt;&lt; endl;
14:
15:       cout &lt;&lt; &quot;&amp;intOne: &quot;  &lt;&lt; &amp;intOne &lt;&lt; endl;
16:       cout &lt;&lt; &quot;&amp;rSomeRef: &quot; &lt;&lt; &amp;rSomeRef &lt;&lt; endl;
17:
18:   return 0;
<TT>19: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: intOne: 5
rSomeRef: 5
&amp;intOne:  0x3500
&amp;rSomeRef: 0x3500
</FONT></PRE>
<BR>
<BR>
<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Your output may differ on the last
	two lines.
<HR>
<BR>
<BR>
</BLOCKQUOTE>
<BR>
<P>
<HR>
<FONT COLOR="#000077"><TT><B>Anaylsis:</B></TT></FONT><TT><B> </B></TT>Once again
<TT>rSomeRef</TT> is initialized as a reference to <TT>intOne</TT>. This time the
addresses of the two variables are printed, and they are identical. C++ gives you
no way to access the address of the reference itself because it is not meaningful,
as it would be if you were using a pointer or other variable. References are initialized
when created, and always act as a synonym for their target, even when the address
of operator is applied.<BR>
For example, if you have a class called <TT>President</TT>, you might declare an
instance of that class as follows:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">President  William_Jefferson_Clinton;</FONT></PRE>
<P>You might then declare a reference to <TT>President</TT> and initialize it with
this object:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">President &amp;Bill_Clinton = William_Jefferson_Clinton;</FONT></PRE>
<P>There is only one <TT>President</TT>; both identifiers refer to the same object
of the same class. Any action you take on <TT>Bill_Clinton</TT> will be taken on
<TT>William_Jefferson_Clinton</TT> as well.</P>
<P>Be careful to distinguish between the <TT>&amp;</TT> symbol on line 9 of Listing
9.2, which declares a reference to <TT>int</TT> named <TT>rSomeRef</TT>, and the
<TT>&amp;</TT> symbols on lines 15 and 16, which return the addresses of the integer
variable <TT>intOne</TT> and the reference <TT>rSomeRef</TT>.</P>
<P>Normally, when you use a reference, you do not use the address of operator. You
simply use the reference as you would use the target variable. This is shown on line
13.</P>
<P>Even experienced C++ programmers, who know the rule that references cannot be
reassigned and are always aliases for their target, can be confused by what happens
when you try to reassign a reference. What appears to be a reassignment turns out
to be the assignment of a new value to the target. Listing 9.3 illustrates this fact.</P>
<BR>
<P><A NAME="Heading8"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 9.3. Assigning
to a reference.</B></FONT>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">
1:     //Listing 9.3
2:      //Reassigning a reference
3:
4:      #include &lt;iostream.h&gt;
5:
6:      int main()
7:      {
8:           int  intOne;
9:           int &amp;rSomeRef = intOne;
10:
11:           intOne = 5;
12:           cout &lt;&lt; &quot;intOne:\t&quot; &lt;&lt; intOne &lt;&lt; endl;
13:           cout &lt;&lt; &quot;rSomeRef:\t&quot; &lt;&lt; rSomeRef &lt;&lt; endl;
14:           cout &lt;&lt; &quot;&amp;intOne:\t&quot;  &lt;&lt; &amp;intOne &lt;&lt; endl;
15:           cout &lt;&lt; &quot;&amp;rSomeRef:\t&quot; &lt;&lt; &amp;rSomeRef &lt;&lt; endl;
16:
17:           int intTwo = 8;
18:           rSomeRef = intTwo;  // not what you think!
19:           cout &lt;&lt; &quot;\nintOne:\t&quot; &lt;&lt; intOne &lt;&lt; endl;
20:           cout &lt;&lt; &quot;intTwo:\t&quot; &lt;&lt; intTwo &lt;&lt; endl;
21:           cout &lt;&lt; &quot;rSomeRef:\t&quot; &lt;&lt; rSomeRef &lt;&lt; endl;
22:           cout &lt;&lt; &quot;&amp;intOne:\t&quot;  &lt;&lt; &amp;intOne &lt;&lt; endl;
23:           cout &lt;&lt; &quot;&amp;intTwo:\t&quot;  &lt;&lt; &amp;intTwo &lt;&lt; endl;
24:           cout &lt;&lt; &quot;&amp;rSomeRef:\t&quot; &lt;&lt; &amp;rSomeRef &lt;&lt; endl;
25:      return 0;
<TT>26: }</TT></FONT>
<FONT COLOR="#0066FF">

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产一区二区| 极品少妇xxxx精品少妇| 国产欧美日产一区| 欧美成人vr18sexvr| 日韩一区二区免费电影| 欧美一级片免费看| 日韩一区二区三区在线观看| 911精品产国品一二三产区| 欧美亚洲动漫另类| 欧美精品日韩综合在线| 3d成人动漫网站| 精品久久久久99| 亚洲国产精品二十页| 亚洲欧洲日产国码二区| 一区二区久久久久久| 亚洲一区影音先锋| 日日摸夜夜添夜夜添精品视频 | 久久久不卡网国产精品一区| 久久久影视传媒| 国产精品第一页第二页第三页| 亚洲日本免费电影| 亚洲二区在线观看| 精品一区二区三区香蕉蜜桃| 不卡一区二区三区四区| 色欧美片视频在线观看在线视频| 欧美日韩一级大片网址| 精品久久人人做人人爽| 亚洲图片欧美激情| 日本成人在线电影网| 国产成人亚洲精品青草天美| 色先锋久久av资源部| 日韩精品在线一区| 亚洲欧美色图小说| 国产综合久久久久久久久久久久| 成人一区二区三区在线观看| 欧美日韩国产一级片| 国产视频在线观看一区二区三区 | 视频在线在亚洲| 国产综合久久久久久久久久久久 | 免费精品视频最新在线| 99在线热播精品免费| 欧美一级日韩不卡播放免费| 亚洲日本乱码在线观看| 国内精品免费**视频| 91国产丝袜在线播放| 国产校园另类小说区| 日本欧美一区二区三区| 色欧美片视频在线观看| 欧美国产综合色视频| 麻豆精品国产91久久久久久| 日本高清不卡在线观看| 中文字幕精品—区二区四季| 精品在线视频一区| 欧美一区二区日韩| 亚洲一区二区在线视频| gogogo免费视频观看亚洲一| 精品国产一区二区三区av性色| 午夜精品一区二区三区电影天堂 | 一区二区三区在线观看欧美| 国产成人午夜精品5599 | 春色校园综合激情亚洲| 91精品黄色片免费大全| 洋洋av久久久久久久一区| 不卡的电视剧免费网站有什么| 日韩一级片在线观看| 天天做天天摸天天爽国产一区| 91丨九色丨蝌蚪丨老版| 国产精品久久久久久一区二区三区 | 色猫猫国产区一区二在线视频| 久久久国际精品| 国产一区二区视频在线| 日韩免费看网站| 奇米在线7777在线精品| 欧美一区二区三区在线看| 亚洲成人tv网| 欧美精品亚洲一区二区在线播放| 亚洲h精品动漫在线观看| 欧美日精品一区视频| 亚洲高清久久久| 精品视频在线视频| 婷婷久久综合九色综合绿巨人| 欧洲视频一区二区| 亚洲第一在线综合网站| 91麻豆精品国产自产在线观看一区 | 中文字幕不卡在线| av在线一区二区| 亚洲激情欧美激情| 欧美精品一二三四| 韩国三级电影一区二区| 国产拍欧美日韩视频二区| 成人精品视频网站| 亚洲欧美福利一区二区| 欧美做爰猛烈大尺度电影无法无天| 一级做a爱片久久| 在线观看91精品国产麻豆| 美女www一区二区| 国产亚洲精品久| 91麻豆国产精品久久| 亚洲国产精品一区二区www| 欧美一区二区性放荡片| 国产一区二区三区久久久 | 欧美精品丝袜中出| 国产做a爰片久久毛片| 国产精品毛片a∨一区二区三区| 色综合咪咪久久| 奇米影视在线99精品| 国产精品久久久久精k8 | 亚洲精品在线观| jizz一区二区| 视频一区国产视频| 国产视频一区在线播放| 精品视频在线看| 国产成人精品亚洲777人妖| 亚洲乱码中文字幕| 日韩丝袜美女视频| 91美女福利视频| 国产一区二区三区免费| 一区二区三区视频在线看| 日韩欧美你懂的| 91福利区一区二区三区| 国产一区二区三区黄视频| 亚洲最快最全在线视频| 国产亚洲美州欧州综合国| 欧美日本视频在线| 99国产精品一区| 黄页网站大全一区二区| 亚洲一级片在线观看| 国产精品久久三| 欧美成人精品3d动漫h| 欧美日韩一区二区三区高清| 国产精品乡下勾搭老头1| 欧美aaaaa成人免费观看视频| 亚洲欧美另类图片小说| 国产精品视频在线看| 精品对白一区国产伦| 91精品国产美女浴室洗澡无遮挡| 99久久精品免费精品国产| 激情图区综合网| 日韩av一级电影| 日韩中文字幕亚洲一区二区va在线| 亚洲视频一二三区| 中文字幕一区二区三区在线观看| 精品免费国产一区二区三区四区| 91精品国产综合久久香蕉的特点 | 在线亚洲免费视频| 色欲综合视频天天天| av激情综合网| 99re在线精品| www.视频一区| 成人毛片在线观看| 菠萝蜜视频在线观看一区| 国产91清纯白嫩初高中在线观看| 国产黑丝在线一区二区三区| 精品影院一区二区久久久| 日本不卡在线视频| 另类综合日韩欧美亚洲| 老司机精品视频在线| 看电影不卡的网站| 国产在线视视频有精品| 国产老肥熟一区二区三区| 懂色av一区二区三区免费观看| 国产麻豆欧美日韩一区| 成人免费视频播放| 色哟哟一区二区| 欧美日韩精品一区视频| 在线播放国产精品二区一二区四区| 欧美精品在线一区二区三区| 欧美日韩www| 精品国产91九色蝌蚪| 欧美激情一区三区| 亚洲影视资源网| 另类调教123区| 国产成人欧美日韩在线电影| 97精品久久久午夜一区二区三区| 在线观看av一区| 日韩欧美的一区| 欧美国产一区二区| 性做久久久久久免费观看| 免费成人在线视频观看| 成人免费毛片高清视频| 91国产福利在线| 日韩免费看的电影| 最新热久久免费视频| 亚洲成a人片在线不卡一二三区| 麻豆91免费观看| 成人激情黄色小说| 欧美精品久久天天躁| 国产婷婷色一区二区三区四区| 亚洲一区二区三区三| 国产乱国产乱300精品| 欧美日韩视频在线第一区 | 亚洲国产精品影院| 狠狠色丁香婷婷综合| 色88888久久久久久影院按摩| 日韩欧美一级二级三级久久久| 国产精品久久久久久久午夜片| 亚洲h动漫在线| 色综合中文字幕国产| 欧美日韩大陆一区二区| ...xxx性欧美|