📄 10.2.2c.htm
字号:
<html>
<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>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.2.2b.htm'" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.3.1.htm'" ></imag></td>
</tr>
</table>
<p> </p>
<table>
<tr>
<td>    </td>
<td class="content">
<p>
当定义一个对象时,我们会在对象的起始地址处插入一个指针指向该对象所在类的动态方法表,这个指针在c++中也被称为虚指针。有了这些准备,当编译c.f()时,就会生成以下的指令:
<p>
1. 在对象c的起始地址取得虚指针;
<p>
2. 从虚指针指向的动态方法表对应的f所在的偏移量处(这是一个常量)获得机器标号p;
<p>
3. 跳转到地址p处继续执行,并保存返回结果。
<p>
根据上面属性和方法的编译方案,程序10.5对应的对象实例如图10.6所示
<p align=center><img src="images/10_6.gif"></p>
</td>
</tr>
</table>
<p> </p>
<table align="right" width="300">
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.2.2b.htm'" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='10.3.1.htm'" ></imag></td>
</tr>
</table>
</body>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -