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

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-04-19 22:30:23

后++  实现

  1. #include <iostream>
  2. #include <cstring>

  3. using namespace std;

  4. class Cvector
  5. {
  6. public:
  7.     Cvector(int m,int n);
  8.     Cvector operator++(int);

  9.     void output();
  10. private:
  11.     int x;
  12.     int y;
  13. };

  14. Cvector::Cvector(int m,int n)
  15. {
  16.     x=m;
  17.     y=n;
  18. }

  19. void Cvector::output()
  20. {
  21.     cout<<x<<","<<y<<endl;
  22. }

  23. Cvector Cvector::operator++(int)
  24. {
  25.     Cvector tmp=(*this);
  26.     ++this->x;
  27.     ++this->y;
  28.     return (tmp);
  29. }
  30. int main()
  31. {
  32.     Cvector v(0,0);
  33.     Cvector tmp= v++;
  34.     v.output();
  35.     tmp.output();

  36.     return 0;
  37. }

  1. ywx@yuweixian:~/yu/c++/chongzai/chong++$ ./chong++1
  2. 1,1
  3. 0,0
  4. ywx@yuweixian:~/yu/c++/chongzai/chong++$


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