多态~
1 #include <iostream> 2 using namespace std; 3 4 class Person 5 { 6 public: 7 int age; 8 int name; 9 virtual void pee() 10 { 11 cout<<"man stand and woman sit"<<endl; 12 } 13 }; 14 15 class man : public Person 16 { 17 void pee() 18 { 19 cout<<"man stand~"<<endl; 20 } 21 }; 22 23 class woman : public Person 24 { 25 void pee() 26 { 27 cout<<"woman sit"<<endl; 28 } 29 }; 30 31 void Gowc(Person *p) 32 { 33 p->pee(); 34 } 35 36 void main() 37 { 38 man *m = new man(); 39 woman *wm =new woman(); 40 Gowc(m); 41 Gowc(wm); 42 }
运行结果是:man stand~ 换行 woman sit。
男人女人都是人,但是撒尿的方式不同~就是的多态~end.