龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC++深入详解:this指针(2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
例2-10 #include iostream.h class point { public: int x; int y; point() { x=0; y=0; } point(int a,int b) { x=a; y=b; } void output() { coutxendlyendl; } void input(int x,int y) { this-x=x; this-y=y; }

  例2-10

  #include <iostream.h>
  class point
  {
  public:
     int x;
     int y;
     point()
     {
       x=0;
       y=0;
     }
     point(int a,int b)
     {
       x=a;
       y=b;
     }
     void output()
     {
       cout<<x<<endl<<y<<endl;
     }
     void input(int x,int y)
     {
       this->x=x;
       this->y=y;
     }
  };
  void main()
  {
     point pt(5,5);
     pt.input(10,10);
     pt.output();
  }

  再编译运行,此时的结果就如预期所料了。

精彩图集

赞助商链接