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

📄 page_913.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_913</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_912.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_913</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_914.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 913</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="Courier New, Courier, Mono New, Courier, Mono" size="2">聽聽聽聽ExtTime();聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽Default聽constructor,<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽setting聽time聽to<br />private:聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽0;0;0聽EST<br />聽聽聽聽ZoneType聽zone;<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">The opening line</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">class聽ExtTime聽:聽public聽Time</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">states that </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> is derived from </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3">. The reserved word </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">public</font><font face="Times New Roman, Times, Serif" size="3"> declares </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> to be a <i>public base class</i> of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3">. This means that all public members of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> (except constructors) are also public members of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3">. In other words, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3">'s member functions </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Set</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Increment</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Write</font><font face="Times New Roman, Times, Serif" size="3"> can also be invoked for </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> objects.* However, the public part of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> specializes the base class by reimplementing (overriding) the inherited functions </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Set</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Write</font><font face="Times New Roman, Times, Serif" size="3"> and by providing its own constructors.</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td>  <td colspan="3" height="12"></td>  <td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td></tr><tr><td colspan="3" height="2"><table cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="2">Overriding Reimplementing a member function inherited from a parent class.</font></td><td></td></tr><tr><td colspan="3" height="2"><table cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table></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 private part of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> declares that a new private member is added: </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">zone</font><font face="Times New Roman, Times, Serif" size="3">. The private members of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> are therefore </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hrs</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">mins</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">secs</font><font face="Times New Roman, Times, Serif" size="3"> (all inherited from </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3">), and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">zone</font><font face="Times New Roman, Times, Serif" size="3">. Figure 16-5 pictures the relationship between the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> classes.</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">This diagram shows that each </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> object has a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> object as a <i>subobject.</i> Every </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ExtTime</font><font face="Times New Roman, Times, Serif" size="3"> is a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3">, and more. C++ uses the terms base class and derived class instead of superclass and subclass. The terms superclass and</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td>  <td colspan="3" height="12"></td>  <td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td></tr><tr><td colspan="3" height="1"><table cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="2">*If a class declaration omits the word </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">public</font><font face="Times New Roman, Times, Serif" size="2"> and begins as </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2"> class DerivedClass : BaseClass </font><font face="Times New Roman, Times, Serif" size="2"> or if it explicitly uses the word </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">private</font><font face="Times New Roman, Times, Serif" size="2">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">class DerivedClass : private BaseClass</font><font face="Times New Roman, Times, Serif" size="2"> then </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">BaseClass</font><font face="Times New Roman, Times, Serif" size="2"> is called a <i>private base class</i> of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">DerivedClass</font><font face="Times New Roman, Times, Serif" size="2">. Public members of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">BaseClass</font><font face="Times New Roman, Times, Serif" size="2"> are <i>not</i> public members of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">DerivedClass</font><font face="Times New Roman, Times, Serif" size="2">. That is, clients of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">DerivedClass</font><font face="Times New Roman, Times, Serif" size="2"> cannot invoke </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">BaseClass</font><font face="Times New Roman, Times, Serif" size="2"> operations on </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">DerivedClass</font><font face="Times New Roman, Times, Serif" size="2"> objects. We do not work with private base classes in this book.</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_912.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_913</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_914.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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