C++之纯虚函数

1. 纯虚函数形式

class Parent
{
public:
    virtual void func1() = 0;
};

  代码中的func1就是纯虚函数,没有函数体,没有函数的具体实现,有virtual,在函数名后面带有“ = 0”形式;

2.对于纯虚函数的注意事项

  1.对含有纯虚函数的类,称为抽象类

  2.抽象类不能实例化,不能new

  3.纯虚函数被充当函数接口使用,函数的具体实现,在子类中实现

3.多重继承

class Father
{
public:
    int a;
};

class Mather
{
public:
    int b;
};

class Child:public Father,public Mather
{
public:
    char c;
};

多重继承,就是说子类有继承多个父类;

4.纯虚函数做接口使用实例

原文地址:https://www.cnblogs.com/weiyouqing/p/9643582.html