Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7651339
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: C/C++

2011-03-30 14:25:06

  1. /****************************************************
  2. * 文件名:
  3. * 功能:多继承简单应用
  4. * 说明:多继承可以看作是多个单继承的组合
  5. * 时间:2011-3-30 --Lzy
  6. ****************************************************/

  7. //多继承

  8. #include <iostream.h>

  9. class A
  10. {
  11. private:
  12.     int a, b;

  13. public:
  14.     A(int x= 0, int y= 0){a = x; b = y;}
  15.     void displayA(){cout<<"A a="<<a<<" b ="<<b<<endl;}
  16. };

  17. class B
  18. {
  19. private:
  20.     int c;

  21. public:
  22.     B(int cc= 0){c = cc;}
  23.     void displayB(){cout<<"B c="<<c<<endl;}
  24. };

  25. class C:public A, public B
  26. {
  27. private:
  28.     int d;

  29. public:
  30.     C(int = 0,int = 0,int = 0,int = 0);
  31.     void displayC(){cout<<"C d="<<d<<endl;}
  32.     void display();
  33. };

  34. C::C(int aa ,int bb ,int cc,int dd):A(aa,bb),B(cc)
  35. {
  36.     d = dd;
  37. }

  38. void C::display()
  39. {
  40.     displayA();
  41.     displayB();
  42.     cout<<"C d="<<d<<endl;
  43. }

  44. void main()
  45. {
  46.     C c1, c2(10,11,12);
  47.     c1.displayA();
  48.     c1.displayB();
  49.     c1.displayC();
  50.     c2.display();
  51. }
阅读(1214) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~