笔记:类似于接口函数以及接口类(具体介绍文档后续更新········)
纯虚函数:
#include<iostream> #include<string> using namespace std; //纯虚函数和抽象类 class A{ public: virtual void fooa()=0; }; class B:public A{ void fooa(){ cout<<"这是纯虚函数···"<<endl; } }; int main(){ A* a=new B(); a->fooa(); delete a; getchar(); return 0; } [点击并拖拽以移动] 运行结果:
纯抽象类:
#include<iostream> #include<string> using namespace std; //纯虚函数和抽象类 class A{ public: virtual void fooa()=0; virtual void foob()=0; }; class B:public A{ public: void fooa(){ cout<<"这是B纯虚函数···"<<endl; } void foob(){ cout<<"bb"<<endl; } }; class C:public A{ public: void fooa(){ cout<<"这是C纯虚函数···"<<endl; } void foob(){ cout<<"cb"<<endl; } }; int main(){ A* a=new B(); a->fooa(); a->foob(); delete a; a=new C(); a->fooa(); a->foob(); getchar(); return 0; }运行结果: