📄 10.2.1.htm
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<body>
<table align="right" width="300">
<tr>
<td>
</imag>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.1.3b.htm'" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.2.2.htm'" ></imag></td>
</tr>
</table>
<p> </p>
<font class="title2"><b>10.2.1 属性</b></font>
<table><tr><td>    </td>
<td class="content">
<p>在程序1.1中,为了估计表达式p1->a1的值,编译器必须生成代码以获得指针p1所指向的对象中属性a1所对应的值。一个简单的办法是编译时在变量p1的环境域中包含一个指针指向类Quadrangle的描述符;这个描述符中含有属性和它们在类中的偏移值的列表。但是由于继承的引入,会出现在运行时变量p1指向的也可能是一个Rectangle或Square对象,那么这时候在Rectangle或Square类中的a1属性对应的偏移值该是什么呢?</p>
<p>对于单继承,即每个派生类只有一个父类的情况,采用最简单的“前置”技术就能解决上面的问题。例如当B从A派生而来时,那些从A继承来的属性被置于B的属性域的最开始,并和它们在A中出现的顺序是相同的。那些从B派生的属性被放在后面,图10.3说明了这点。</p>
<p align=center><img src="images/10_3.gif"> </p>
</td></tr></table>
<table align="right" width="300">
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.1.3b.htm'" ></imag></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.2.2.htm'" ></imag></td>
</tr>
</table>
</body>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -