这可以是抽象基类的定义:包含仅纯虚方法,通常作为派生类的接口规范。抽象基类还可以包含其他方法(也是虚方法)。
根据C++标准(第10.4节,抽象类,我强调)的定义:
在这个例子中,An abstract class is a class that can be used only as a base class of some other class; no objects of an abstract class can be created except as subobjects of a class derived from it. A class is abstract if it has at least one pure virtual function. [ Note: Such a function might be inherited: see below. —end note ]
class point { / ... / }; class shape { // abstract class point center; public: point where() { return center; } void move(point p) { center=p; draw(); } virtual void rotate(int) = 0; // pure virtual virtual void draw() = 0; // pure virtual };
shape
包含了两个纯虚方法(因此它是一个抽象类),但也包含了两个非虚方法。这没有问题。因此,你最初的定义,即抽象类只包含纯虚函数,太过严格。只要至少有一个纯虚函数就足够了。