C ++中的抽象类和纯虚函数

Abstract Class is a class which contains atleast one Pure Virtual function in it. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.

抽象类是一个其中至少包含一个纯虚函数的类。 抽象类用于为其子类提供接口。 继承抽象类的类必须为纯虚函数提供定义,否则它们也将成为抽象类。

抽象类的特征 (Characteristics of Abstract Class)

  1. Abstract class cannot be instantiated, but pointers and refrences of Abstract class type can be created.

    无法实例化Abstract类,但是可以创建Abstract类类型的指针和引用。

  2. Abstract class can have normal functions and variables along with a pure virtual function.

    抽象类可以具有普通函数和变量以及纯虚函数。

  3. Abstract classes are mainly used for Upcasting, so that its derived classes can use its interface.

    抽象类主要用于Upcasting

你可能感兴趣的:(抽象类,c++,java,php,python)