当前在线人数16224
首页 - 分类讨论区 - 电脑网络 - 葵花宝典版 -阅读文章
未名交友
[更多]
[更多]
文章阅读:Re: a C++ interview question
[同主题阅读] [版面: 葵花宝典] [作者:woolf] , 2005年06月03日23:41:24
woolf
进入未名形象秀
我的博客
[上篇] [下篇] [同主题上篇] [同主题下篇]

发信人: woolf (老鳄鱼), 信区: Programming
标  题: Re: a C++ interview question
发信站: Unknown Space - 未名空间 (Fri Jun  3 23:47:21 2005), 转信

Please refer to "Effective C++" by Scott Meyers, item 14

--quote---
Finally, it's worth mentioning that it can be convenient to declare pure
virtual destructors in some classes. Recall that pure virtual functions
result in abstract classes — classes that can't be instantiated (i.e., you
can't create objects of that type). Sometimes, however, you have a class
that you'd like to be abstract, but you don't happen to have any functions
that are pure virtual. What to do? Well, because an abstract class is
intended to be used as a base class, and because a base class should have
a virtual destructor, and because a pure virtual function yields an abstract
class, the solution is simple: declare a pure virtual destructor in the
class you want to be abstract.

There is one twist, however: you must provide a definition for the pure
virtual destructor.

You need this definition, because the way virtual destructors work is
that the most derived class's destructor is called first, then the
destructor of each base class is called. That means that compilers will
generate a call to ~AWOV even though the class is abstract, so you have
to be sure to provide a body for the function. If you don't, the linker
will complain about a missing symbol, and you'll have to go back and
add one.
--end quote--

What kind of job are you interviewing ? A C++ language lawyer position?


【 在 gator (小朋友~~鳄鱼来了) 的大作中提到: 】
: when do you use PURE virtual destructor ?


--
※ 来源:.Unknown Space - 未名空间 mitbbs.com.[FROM: 169.229.]

[上篇] [下篇] [同主题上篇] [同主题下篇]
[转寄] [转贴] [回信给作者] [修改文章] [删除文章] [同主题阅读] [从此处展开] [返回版面] [快速返回] [收藏] [举报]
 
回复文章
标题:
内 容:

未名交友
将您的链接放在这儿

友情链接


 

Site Map - Contact Us - Terms and Conditions - Privacy Policy

版权所有,未名空间(mitbbs.com),since 1996