I was reversing some C++ code and encountered following function.sub_106C0A0 proc nearvar_10= dword ptr -10hvar_C= dword ptr -0Chvar_4= dword ptr -4push    0FFFFFFFFhpush    offset SEH_106C0A0mov     eax, large fs:0push    eaxmov     large fs:0, esppush    ecxpush    esimov     esi, ecxpush    edilea     edi, [esi+4]push    30hmov     ecx, edimov     [esp+1Ch+var_10], esimov     dword ptr [esi], offset off_12C0680call    struc_13_ctormov     dword ptr [edi], offset off_12C057C ; another vtable init ?This function passes this pointer of some object (struc_13), which is esi+4, to the struc_13_ctor. Inside the struc_13_ctor function, it initializes the vtable pointer and other member variables. ; int __thiscall struc_13_ctor(struc_13 *this, __int16 a2)struc_13_ctor proc neararg_0= word ptr  4mov     dx, [esp+arg_0]mov     eax, ecxxor     ecx, ecxmov     dword ptr [eax], offset struc_13_vtablemov     [eax+4], ecxmov     [eax+8], ecxmov     [eax+0Ch], dxmov     [eax+0Eh], cxmov     [eax+14h], ecxmov     [eax+10h], ecxretn    4struc_13_ctor endpHowever after returning from struc_13_ctor, it overwrites the vtable pointer with the new value, which is off_12C057C in this case. call    struc_13_ctormov     dword ptr [edi], offset off_12C057C ; another vtable init ?I have seen this kind of behaviors a lot while looking at ctor functions, but never understood why this happens. 
Questions about reversing object oriented code(initializing vtables in ctors)
c++
I think the c++ code would look something like this:// has vtbl struc_13_vtable// has constructor struc_13_ctorstruct struc_13 {    int  a,b;    short c,d;    int e,f;    struc_13(short x)       : a(0), b(0), c(x), d(0), e(0), f(0)    { }    virtual void someotherfn();};// has vtbl off_12C057C// has inlined constructorstruct derivedmember : struc_13 {    derivedmember() : struc_13(0x30)    { }    virtual void someotherfn();};// has vtbl off_12C0680// has constructor sub_106C0A0struct A {    derivedmember  member;    virtual void somefn();};