⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page_823.html

📁 Programming and Problem Solving with C++
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">	<html>		<head>			<title>page_823</title>			<link rel="stylesheet" href="reset.css" type="text/css" media="all">			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		</head>		<body>		<table summary="top nav" border="0" width="100%">			<tr>				<td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_822.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_823</strong></td>				<td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_824.html">next page&nbsp;&gt;</a></td>			</tr>					<tr>				<td align="left" colspan="3" style="background: #ffffff; padding: 20px;">    <table border="0" width="100%" cellpadding="0"><tr><td align="center">  <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td>  <td align="right"></td>  </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 823</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">The index [0] is correctly attached to the identifier </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">gradeBook</font><font face="Times New Roman, Times, Serif" size="3"> because </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">gradeBook</font><font face="Times New Roman, Times, Serif" size="3"> is the name of an array. Furthermore, the expression</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">gradeBook[0]</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">denotes a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">, so the dot operator selects the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">gpa</font><font face="Times New Roman, Times, Serif" size="3"> member of this </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">Another potential source of confusion when working with </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">structs</font><font face="Times New Roman, Times, Serif" size="3"> is the scope of member names. We said earlier that member names must be unique within a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">. Additionally, we mentioned in Chapter 8 that there are three kinds of scope in C++: local scope, file (global) scope, and <i>class scope.</i> Class scope applies to the member names within </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">structs</font><font face="Times New Roman, Times, Serif" size="3">, unions, and classes (the topic of Chapter 15). To say that a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3"> member name has class scope means that the name is local to that </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">. If the same identifier happens to be declared outside the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">, the two identifiers are unrelated. For example, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">name</font><font face="Times New Roman, Times, Serif" size="3"> is such a meaningful identifier that it might be used logically in more than one </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">. Look at the following declarations:</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">const聽int聽CLASS_SIZE聽=聽120;<br />const聽int聽NUM_CITIES聽=聽1000;<br /><br />typedef聽char聽String20[21];<br /><br />enum聽YearType聽{FRESHMAN,聽SOPHOMORE,聽JUNIOR,聽SENIOR};<br /><br />struct聽PersonType<br /><br />{<br />聽聽聽聽String20聽name;<br />聽聽聽聽YearType聽year;<br />聽聽聽聽int聽聽聽聽聽聽age;<br />};<br />struct聽CityType<br />{<br />聽聽聽聽String20聽name;<br />聽聽聽聽String20聽state;<br />聽聽聽聽int聽聽聽聽聽聽elevation;<br /><br />};<br /><br />PersonType聽oneStudent;<br />String20聽聽聽name;<br />PersonType聽roster[CLASS_SIZE];<br />CityType聽聽聽city[NUM_CITIES];</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">The declarations are valid, even though the identifier </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">name</font><font face="Times New Roman, Times, Serif" size="3"> is declared in three places: as a string variable, a member name in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PersonType聽struct</font><font face="Times New Roman, Times, Serif" size="3">, and a member name in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CityType聽struct</font><font face="Times New Roman, Times, Serif" size="3">. No ambiguities arise because </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">name</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">oneStudent.name</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">roster[i].name</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">city[i].name</font><font face="Times New Roman, Times, Serif" size="3"> are all unique. No ambiguities arise for the compiler, that is; but ambiguities can arise for</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><p><font size="0"></font></p>  </td>			</tr>				<tr>				<td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_822.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_823</strong></td>				<td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_824.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -