纯虚函数和抽象类

纯虚函数,就是抽象类

 1 #include <iostream>
 2 #include "string"
 3 using namespace std;
 4 
 5 class Base
 6 {
 7 public:
 8     //只要包含一个纯虚函数,就是抽象类
 9     virtual void func() = 0;
10 };
11 
12 class Son :public Base
13 {
14 public:
15     void func()
16     {
17         cout << "子类重写方法" << endl;
18     }
19 };
20 
21 void test(Base *base)
22 {
23     base->func();
24 }
25 int main()
26 {
27     //抽象类无法实例化
28     test(new Son);
29 
30     system("pause");
31     return 0;
32 }
原文地址:https://www.cnblogs.com/rtblogs/p/12027291.html