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

📄 page_1000.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_1000</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_999.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1000</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_1001.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 1000</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">As with any nonarray variable in C++, a class object can be passed to a function either by value or by reference. Because C++ defines initialization to include pass-by-value, copy-constructors are vitally important when class objects point to dynamic data. Assume that we did not include a copy-constructor for the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Date</font><font face="Times New Roman, Times, Serif" size="3"> class, and assume that the following call to the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DoSomething</font><font face="Times New Roman, Times, Serif" size="3"> function uses pass-by-value:</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">int聽main()<br />{<br />聽聽聽聽Date聽quizDate(2,聽18,聽1998,聽Geography聽quiz);<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<br />聽聽聽聽DoSomething(quizDate);<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.</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">Without a copy-constructor, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">quizDate</font><font face="Times New Roman, Times, Serif" size="3"> would be copied to the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DoSomething</font><font face="Times New Roman, Times, Serif" size="3"> function's formal parameter using a shallow copy. A copy of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">quizDate's</font><font face="Times New Roman, Times, Serif" size="3"> dynamic array would <i>not</i> be created for use within </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DoSomething</font><font face="Times New Roman, Times, Serif" size="3">. Both </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">quizDate</font><font face="Times New Roman, Times, Serif" size="3"> and the formal parameter within </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DoSomething</font><font face="Times New Roman, Times, Serif" size="3"> would point to the same dynamic array (see Figure 17-13). If the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DoSomething</font><font face="Times New Roman, Times, Serif" size="3"> function were to modify the dynamic array (thinking it is working on a <i>copy</i> of the original), then after the function returns, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">quizDate</font><font face="Times New Roman, Times, Serif" size="3"> would point to a corrupted dynamic array.</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" width="100%"><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 align="center"><font face="Times New Roman, Times, Serif" size="3"><img src="6723035ef69cba97ead39e6eec9427e4.gif" border="0" alt="1000-01.gif" width="480" height="323" /></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" width="100%"><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 align="center"><font face="Times New Roman, Times, Serif" size="2">Figure聽17-13<br />Shallow聽Copy聽Caused聽by聽Pass-by-Value聽without聽a聽Copy-Constructor</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_999.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1000</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_1001.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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