????????????

????????????????е?????????vptr?????????????????vtable????????????????????????????????????????????????????????vptr??????????????

????c++???

class X {
private:
    int i;
public:
    virtual void set(int ii) {
        i = ii;
    }
    ~X() {}
};
class Y : public X {
private:
    int i;
};
int main() {
    Y y;
}

??????Y?????????????

??1Y@@QAE@XZ PROC                    ; Y::~Y?? COMDAT
; _this$ = ecx
    push    ebp
    mov    ebp?? esp
    push    ecx;?????????y?????????????
    mov    DWORD PTR _this$[ebp]?? ecx;ecx?б???y???????????浽???????
    mov    ecx?? DWORD PTR _this$[ebp];??y????????(y?????????????????????????)????ecx????????????????????X??????????
    call    ??1X@@QAE@XZ                ; ??????X??????????
    mov    esp?? ebp
    pop    ebp
    ret    0
??1Y@@QAE@XZ ENDP

?????????????????????????y???????????????????????????????????????????????????????y????????????????棬????г????y????vptr????????Y?????vtable???????

????????????X???????????????

??1X@@QAE@XZ PROC                    ; X::~X?? COMDAT
; _this$ = ecx

; 9    :     ~X() {}

    push    ebp
    mov    ebp?? esp
    push    ecx;????????????????????????
    mov    DWORD PTR _this$[ebp]?? ecx;?????????????????????????????
    mov    eax?? DWORD PTR _this$[ebp];????????????eax
    mov    DWORD PTR [eax]?? OFFSET ??_7X@@6B@;??????vtable??????????????????????? ??????????????е?vptr???
    mov    esp?? ebp
    pop    ebp
    ret    0
??1X@@QAE@XZ ENDP

??????????????????г????vptr???????

???????????

????c++??????£?

class X {
private:
    int i;
public:
    virtual void f() = 0;//???麯??
    X() {
       i = 1;
    }
};

class Y : public X {//Y?????X
private:
   int j;
public:
    virtual void f() {
        j = 2;
    }
};

 


int main() {
 Y y;
}

???????????X?????????????Y?????????????

????????Y????????????

??0Y@@QAE@XZ PROC                    ; Y::Y?? COMDAT
; _this$ = ecx
    push    ebp
    mov    ebp?? esp
    push    ecx;???????????????????
    mov    DWORD PTR _this$[ebp]?? ecx;??ecx(???????????????)????????????
    mov    ecx?? DWORD PTR _this$[ebp];???????????????ecx?????????????(this???)???????????????
    call    ??0X@@QAE@XZ                ; ???????????????
    mov    eax?? DWORD PTR _this$[ebp];?????????????eax t
    mov    DWORD PTR [eax]?? OFFSET ??_7Y@@6B@;????????vtable?????浽?????????????????棬?????????????vptr
    mov    eax?? DWORD PTR _this$[ebp];??????????????eax????????????????????????????????
    mov    esp?? ebp
    pop    ebp
    ret    0
??0Y@@QAE@XZ ENDP

????????X???????????

??0X@@QAE@XZPROC                    ; X::X?? COMDAT
; _this$ = ecx

; 6    :     X() {

    push    ebp
    mov    ebp?? esp
    push    ecx;???????????洢??????????(??this???)?????
    mov    DWORD PTR _this$[ebp]?? ecx;?????????????浽??????
    mov    eax?? DWORD PTR _this$[ebp];?????????????????eax
    mov    DWORD PTR [eax]?? OFFSET 7X@@6B?????????vtable(????????????????vtable???????????????д????麯???????????????????λ??)?????浽?????????????????? ??????????????vptr???

; 7    :        i = 1;

    mov    ecx?? DWORD PTR _this$[ebp];???????????????ecx
    mov    DWORD PTR [ecx+4]?? 1;??1?浽????????????4byte?????????????????????i???

; 8    :     }

    mov    eax?? DWORD PTR _this$[ebp];?????????????eax ??????????????????????????????
    mov    esp?? ebp
    pop    ebp
    ret    0
0X@@QAE@XZ ENDP