110.纯虚函数
1 #include <iostream> 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 virtual void go() 8 { 9 cout << "123" << endl; 10 } 11 12 //纯虚函数,有纯虚函数的类不能创建对象 13 virtual void run() = 0; 14 }; 15 16 class live 17 { 18 public: 19 //纯虚函数作为接口 20 //一旦继承了,必须实现虚函数的接口 21 virtual void life() = 0; 22 virtual void sleep() = 0; 23 }; 24 25 class people :public live 26 { 27 public: 28 virtual void think() = 0; 29 }; 30 31 class birdpeople :public people 32 { 33 public: 34 virtual void fly() 35 { 36 cout << "i can fly" << endl; 37 } 38 void life() 39 { 40 cout << "i can live every time" << endl; 41 } 42 void sleep() 43 { 44 cout << "i can sleep" << endl; 45 } 46 void think() 47 { 48 cout << " i can think" << endl; 49 } 50 }; 51 52 void main() 53 { 54 //myclass *p = new myclass; 55 //p->go(); 56 birdpeople aa; 57 cin.get(); 58 }