纯虚函数是一种特殊的虚函数,在许多情况下,在基类中不能对虚函数给出有意义的实现,而把它声明为纯虚函数,它的实现留给该基类的派生类去做。这就是纯虚函数的作用。
为纯虚函数所生成的代码如列表 1 中所示。
The code generated for the pure virtual function is shown in Listing 1.
这个例子的性能和纯虚函数表例子是相同的。
The performance of this sample and the pure vtable-based sample are exactly identical.
类包含或者继承一个或多个纯虚函数,这样的类就是抽象基类。
A class containing (or inheriting) one or more pure virtual functions is an abstract base class.
应用推荐