您的位置:首页 > 编程语言 > C语言/C++

C++之一元操作符重载

2008-03-23 09:08 369 查看
//成员函数方式实现一元操作符重载
  #include<iostream.h>
  class temp
  {
  private:
   int x,y;
  public:
   void operator ++();//++处应为C++存在的操作符
  };
  void temp::operator ++()
  {
   x++;
   y++;
  }
  main()
  {
   int x=5;
   int y=6;
   int z;
   z=++x;
   cout << "x=5";
   cout << " z=++x";
   cout << "/n";
   cout << "z=" << z;
   cout << "而";
   cout << " x=" << x;
   cout << "/n";
   cout << "/n";
   z=++y;
   cout << "y=6";
   cout << " z=++y";
   cout << "/n";
   cout << " z=" << z;
   cout << "而";
   cout << "y=" << y;
   cout <<"/n";
   return 0;
  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: