zoukankan      html  css  js  c++  java
  • 006 this指针原理

    /*
    目录:
       一 this指针原理
    */

    一 this指针原理

    class CTest
    {
    public:
        CTest(int nNum)
        {
            this->nNum = nNum;
        }
        ~CTest()
        {
    
        }
        void Print()
        {
            cout << nNum << endl;
        }
    private:
        int nNum;
    };
    
    
    int main(int argc, char *argv[], char **envp)
    {
        CTest c(0x11);
        c.Print();
    
        return 0;
    }
    
    // 反汇编
    // 调用函数
    int main(int argc, char *argv[], char **envp)
    {
       136:     CTest c(0x11);
    0041A8BD  push        11h  
    0041A8BF  lea         ecx,[c]                      // 获取地址 : ecx  - 变量c地址
    0041A8C2  call        CTest::CTest (0411983h)  
    0041A8C7  mov         dword ptr [ebp-4],0  
        return 0;
    }
    
    
    // 别调函数
       114: class CTest
       115: {
       116: public:
       117:     CTest(int nNum)
    004122F0  push        ebp  
    004122F1  mov         ebp,esp  
    004122F3  sub         esp,0CCh  
    004122F9  push        ebx  
    004122FA  push        esi  
    004122FB  push        edi  
    004122FC  push        ecx                      // 压栈参数 : ecx - 变量c地址
    004122FD  lea         edi,[ebp-0CCh]  
    00412303  mov         ecx,33h  
    00412308  mov         eax,0CCCCCCCCh  
    0041230D  rep stos    dword ptr es:[edi]  
    0041230F  pop         ecx                      // 出栈参数 : ecx - 变量c地址    
    00412310  mov         dword ptr [this],ecx  // 参数赋值 : ecx - 隐藏变量this指针; 此时this指针指向mian函数中变量c地址。
       118:     {
       119:         this->nNum = nNum;
    00412313  mov         eax,dword ptr [this]  
    00412316  mov         ecx,dword ptr [nNum]  
    00412319  mov         dword ptr [eax],ecx  
       120:     }
            }
       
       
  • 相关阅读:
    C# SocketUdpServer
    C# HttpHelper
    控制台禁止操作
    Modbus Com SerialPort
    postgresql 备份与恢复
    Firebird 表字段查询
    Postgresql 连接更新
    第 1 章 计算机组成与体系结构 1.1计算机系统组成
    系统架构设计师教程(第4版)
    阿里十年架构师用一张图告诉你什么是系统架构师
  • 原文地址:https://www.cnblogs.com/huafan/p/11619445.html
Copyright © 2011-2022 走看看