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

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-04-19 21:28:45



下面实现了简单的 前++  后++
  1. 前++
  2. int operator++(int a)
  3. {
  4.     a=a+1;
  5.     return a;
  6. }

  7. 后++
  8. int poretor++(int a,int)//参数个数区别上个函数
  9. {
  10.   int b=a;
  11.   a=a+1;
  12.   reutrn b;
  13. }

前++

  1. vector &operator++(vector *this)  //这里可以省  略 vector *this
  2. {
  3.   ++this->x
  4.   ++this->y;
  5.   return (*this);
  6. }

后++

  1. vector operator++(vector *this,int)
  2. {
  3.   vector tmp=*this;
  4.   ++this->x;
  5.   ++this->y;
  6.   return tmp;
  7. }








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