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

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-04-19 22:16:39


实现前++


  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++();

  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++()
  24. {
  25.     ++this->x;
  26.     ++this->y;
  27.     return (*this);
  28. }
  29. int main()
  30. {
  31.     Cvector v(0,0);
  32.     Cvector tmp= ++v;
  33.     v.output();
  34.    tmp.output();

  35.     return 0;
  36. }

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




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