问一道全英文的C++题目,求答案!

来源:百度知道 编辑:UC知道 时间:2024/05/30 20:54:22
Why should a class have a pure virtual member functions?

a.Pure virtual member functions allow templated calsses to be used with friend functions.

b.Making a member functions pure virtual guaranteesb that it is implemented in derived classes that are instantiated

c.Pure virtual member functions maximize the execution speed of the function providing that memory is not a premium

d.It cannot. Only destructors can be pure virtual

e.Pure virtual member functions maximize the memory efficiency providing that execution speed is not a premium
晕,这是单选题,还有人能回答吗?

为什么类具有纯虚拟成员函数(纯虚函数)?
a.纯虚函数允许friend 函数中做为模板类来使用 。
b.使得一个成员函数实现虚函数,这是执行派生类的实例
c.纯虚函数最大化函数的执行速度,提供内存的性能优化在没有内存泄露的情况下。
d.不能实现。只有析构函数可以使用纯虚拟函数
e.纯虚函数最大化内存执行效率,提供一个没有内存泄露的运行。
-----------------------------------------------------

我个人答案为 B

原因如下 :
纯虚函数是在基类中声明的虚函数,它在基类中没有定义,但要求任何派生类都要定义自己的实现方法
使用纯虚函数原因:
1、为了方便使用多态特性,我们常常需要在基类中定义虚拟函数。
2、在很多情况下,基类本身生成对象是不合情理的。

至于内存泄露问题一般而言
如果一个类是作为基类使用,那么他的虚构函数一定要是虚的,即用virtual关键字(参数为零则为纯虚函数). 否则会有内存泄漏。
因此与一个类是否使用纯虚函数没有太大联系。

--------------------------------------
5555555 翻译了半天敲字半天 结果按了个ESC都没了 又重新打 累的哭!
楼主我那么辛苦 给点分吧 ~~~~~~~~~~~~~~~~~~~~~~

ab