this指針的作用

//this指針問題  2012年7月18日0:37:13
#include <iostream>
using namespace std;
 class point 
 {
 public:
     int x,y;
    point(int a,int b)
     {
        x= a;
        y = b;
     }
     void input(int x,int y )
     {     
        this->x= x;
        this->y =y;
     }      
     void output()
     {
         cout<<x<<y;

     }
 };
 int main()
 {
     point a(5,5);
      a.input(10,10);
      a.output();
     return 0; 
 }

main函數的彙編代碼:
這裏寫圖片描述
構造函數的彙編代碼:
這裏寫圖片描述
可以看出通過函數調用__fastcall,寄存器傳值,先將參數保存在臨時變量中,然後通過this指針得到相應的地址,在通過mov指令將數據轉移到內存中去

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章