首页 新闻 会员 周边 捐助

C++ 腾讯2010笔试

0
[已解决问题] 解决于 2009-11-13 21:27
<p class="MsoNormal" style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt;"><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: Arial;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">1.</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: small;"><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt;" lang="EN-US">C++</span><span style="font-family: 宋体; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">将父类的析构函数定义为虚函数,下列正确的是哪个?</span><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt;" lang="EN-US"></span></span></p> <p class="MsoNormal" style="text-indent: -21pt; margin: 0cm 0cm 0pt 42pt; mso-list: l0 level2 lfo1; tab-stops: list 42.0pt;"><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: Arial;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">a)</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: small;"><span style="font-family: 宋体; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">释放父类指针时能正确释放子类对象</span><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt;" lang="EN-US"></span></span></p> <p class="MsoNormal" style="text-indent: -21pt; margin: 0cm 0cm 0pt 42pt; mso-list: l0 level2 lfo1; tab-stops: list 42.0pt;"><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: Arial;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">b)</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: small;"><span style="font-family: 宋体; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">释放子类指针时能正确释放父类对象</span><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt;" lang="EN-US"></span></span></p> <p class="MsoNormal" style="text-indent: -21pt; margin: 0cm 0cm 0pt 42pt; mso-list: l0 level2 lfo1; tab-stops: list 42.0pt;"><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: Arial;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">c)</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: small;"><span style="font-family: 宋体; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这样做是错误的</span><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt;" lang="EN-US"></span></span></p> <p class="MsoNormal" style="text-indent: -21pt; margin: 0cm 0cm 0pt 42pt; mso-list: l0 level2 lfo1; tab-stops: list 42.0pt;"><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: Arial;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">d)</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;"><span style="font-size: small;">以上全错</span></span><span style="font-family: Arial; letter-spacing: 0.4pt; color: black; mso-bidi-font-size: 10.5pt;" lang="EN-US"></span></p>
︶ㄣ第二名的主页 ︶ㄣ第二名 | 初学一级 | 园豆:147
提问于:2009-11-11 19:26
< >
分享
最佳答案
0

父类的析构函数必须定义为虚函数,这个可以在effective C++中看到,具体是哪个条款记不太清楚了。

C++的多态肯定是使用父类的指针指向子类的对象,所以肯定是释放子类的对象,如果不使用虚函数的话,父类的指针就只能够释放父类的对象。

cnyao | 菜鸟二级 |园豆:259 | 2009-11-11 19:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册