Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7549314
  • 博文数量: 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-29 19:49:53

  1. /****************************************************
  2. * 文件名:例九
  3. * 功能:常类型
  4. * 说明:常对象只能引用常成员函数
  5.         在类中定义Const数据成员时,要通过成员初始化列表
  6.         的方式来实现构造函数数据成员的初始化
  7. * 时间:2011-3-29      --Lzy
  8. /****************************************************/
  9. #include <iostream.h>

  10. class MyClass
  11. {
  12. private:
  13.     int x, y;

  14. public:
  15.     MyClass(int xx= 0, int yy= 0){x = xx; y = yy;}
  16.     void display()const;            //常成员函数

  17.     void display();
  18. };

  19. void MyClass::display()const
  20. {
  21.     cout<<x<<"----------"<<y<<endl;
  22. }

  23. void MyClass::display()
  24. {
  25.     cout<<x<<"**********"<<y<<endl;
  26. }

  27. void main()
  28. {
  29.     MyClass obj(100, 99);
  30.     obj.display();
  31.     
  32.     const MyClass ob2(200, 199);
  33.     ob2.display();
  34. }
阅读(1221) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~