Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4213677
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-05-27 23:58:54



  1. #include <iostream>

  2. using namespace std;

  3. class Point
  4. {
  5. private:
  6.     int x, y;
  7. public:          // int xx = 1, int yy =2 ;缺省,
  8.                 //在 main中,没有赋值,将缺省使用  xx = 1, int yy = 2;
  9.     Point(int xx = 1, int yy = 2){x= xx; y = yy;}
  10.     ~Point();
  11.     int getx(){return x;}
  12.     int gety(){return y;}
  13. };

  14. Point::~Point()
  15. {
  16.     cout << "bye ~Point()" << endl;
  17. }
  18. int main()
  19. {
  20.     Point a(3, 43);
  21.     cout << a.getx() << endl;
  22.     cout << a.gety() << endl;

  23.     return 0;
  24. }
  1. ywx@yuweixian:~/yu/c$ ./t
  2. 3
  3. 43
  4. bye ~Point()

当我们修改 主函数 ,使用缺省的参数
  1. int main()
  2. {
  3.         Point a;
  4.         cout << a.getx() << endl;
  5.         cout << a.gety() << endl;

  6.         return 0;
  7. }
  1. ywx@yuweixian:~/yu/c$ ./t
  2. 1
  3. 2
  4. bye ~Point()

阅读(967) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~