class Base
public:
//这是一个虚函数
virtual void vir_func()
cout << "This is a virtual function of Base" << endl;
//这是一个纯虚函数
virtual void pure_vir_func() = 0;
};
#include <iostream>
using namespace std;
class Base
public:
//这是一个虚函数
virtual void vir_func()
cout << "This is a virtual function of Base" << endl;
//这是一个纯虚函数
virtual void pure_vir_func() =0;
class Derive : Base
public:
void vir_func()
cout << "This is a virtual function of Derive" << endl;
void pure_vir_func()
cout << "This is a pure virtual function of Derive" << endl;
int main()
// Base b; //企图实例化抽象类,编译器报错
// b.vir_func();
Derive d;
d.vir_func();
d.pure_vir_func();
return 0;
}
输出:
This is a virtual function of Derive
This is a pure virtual function of Derive
class Base
public:
//这是一个虚函数
virtual void vir_func()
cout << "This is a virtual function of Base" << endl;
//这是一个纯虚函数
virtual void pure_vir_func() =0
cout << "This is a pure virtual function of Base" << endl;
};