多态从实现的角度分为:静态多态和动态多态
 
静态多态也叫做编译时多态
动态多态也叫做运行时多态
函数重载是多态的一种实现形式:
重载分为:

1.相同函数不同参数和类型的重载
2.不同类,相同函数重载

第二种的实现:
 
  
  1. #include <iostream>  
  2. using namespace std;  
  3. //定义father类  
  4. class father  
  5. {  
  6. //定义私有成员  
  7. private:  
  8.     int height;  
  9.     int weight;  
  10. //定义公有成员  
  11. public:  
  12.     int showh(int h)  
  13.     {  
  14.         height = h;  
  15.         return height;   
  16.     }  
  17.     int showw(int w)  
  18.     {  
  19.         weight = w;  
  20.         return weight;  
  21.     }  
  22. };  
  23. //son继承father  
  24. class son:public father  
  25. {  
  26. //son的私有成员  
  27. private:  
  28.     int height;  
  29.     int weight;  
  30. //son的公有成员  
  31. public:  
  32.     int showh(int h)  
  33.     {  
  34.         height = h;  
  35.         return height;  
  36.     }  
  37.     int showw(int w)  
  38.     {  
  39.         weight = w;  
  40.         return weight;  
  41.     }  
  42.     };  
  43.  
  44. //主函数  
  45. int main()  
  46. {  
  47.     //创建father对象  
  48.     father liming;  
  49.     cout<<"父亲的身高是: "<<liming.showh(170)<<endl;  
  50.     cout<<"父亲的体重是: "<<liming.showw(120)<<endl;  
  51.     //创建son对象  
  52.     son lilei;  
  53.     cout<<"儿子的身高是: "<<lilei.showh(160)<<endl;  
  54.     cout<<"儿子的体重是: "<<lilei.showw(100)<<endl;  
  55.     //儿子调用父亲的身高  
  56.     cout<<"父亲的身高是: "<<lilei.father::showh(170)<<endl;  
  57.     return 0;  
  58. }