- 论坛徽章:
- 0
|
构造函数?
原帖由 "THEBEST" 发表:
紫扔行楹??睦嗖呕嵊行楸砩??有虚表才会有vptr.
你说其初始化是在ctro之前还是里面.你说ctor之前是什么时候?是进入函数体之前?如果是的话,那么vptr是在函数体中初始化的.所有的构造当然都是在构造函数中完成,你?.........
- .file "test.cpp"
- .lcomm __ZSt8__ioinit,16
- .def ___main; .scl 2; .type 32; .endef
- .text
- LC0:
- .ascii "pause\0"
- .align 2
- .globl _main
- .def _main; .scl 2; .type 32; .endef
- _main:
- pushl %ebp
- movl %esp, %ebp
- subl $56, %esp
- andl $-16, %esp
- movl $0, %eax
- movl %eax, -28(%ebp)
- movl -28(%ebp), %eax
- call __alloca
- call ___main
- leal -24(%ebp), %eax
- movl %eax, (%esp)
- call __ZN1BC1Ev
- movl $LC0, (%esp)
- call _system
- movl $0, %eax
- leave
- ret
- .align 2
- .def __Z41__static_initialization_and_destruction_0ii; .scl 3; .type 32; .endef
- __Z41__static_initialization_and_destruction_0ii:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- cmpl $65535, 12(%ebp)
- jne L3
- cmpl $1, 8(%ebp)
- jne L3
- movl $__ZSt8__ioinit, (%esp)
- call __ZNSt8ios_base4InitC1Ev
- L3:
- cmpl $65535, 12(%ebp)
- jne L2
- cmpl $0, 8(%ebp)
- jne L2
- movl $__ZSt8__ioinit, (%esp)
- call __ZNSt8ios_base4InitD1Ev
- L2:
- leave
- ret
- LC1:
- .ascii ",\0"
- .section .text$_ZN1BC1Ev,"x"
- .linkonce discard
- .align 2
- .globl __ZN1BC1Ev
- .def __ZN1BC1Ev; .scl 2; .type 32; .endef
- __ZN1BC1Ev:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- movl 8(%ebp), %eax
- movl %eax, (%esp)
- call __ZN1AC2Ev
- movl 8(%ebp), %eax
- movl $__ZTV1B+8, (%eax)
- movl 8(%ebp), %eax
- movl $20, 8(%eax)
- movl 8(%ebp), %eax
- movl 4(%eax), %eax
- movl %eax, 4(%esp)
- movl $__ZSt4cout, (%esp)
- call __ZNSolsEi
- movl $LC1, 4(%esp)
- movl %eax, (%esp)
- call __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
- movl %eax, %edx
- movl 8(%ebp), %eax
- movl 8(%eax), %eax
- movl %eax, 4(%esp)
- movl %edx, (%esp)
- call __ZNSolsEi
- movl $__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, 4(%esp)
- movl %eax, (%esp)
- call __ZNSolsEPFRSoS_E
- movl 8(%ebp), %eax
- movl %eax, (%esp)
- call __ZN1B4sizeEv
- leave
- ret
- .globl __ZNSt15basic_streambufIcSt11char_traitsIcEE13_S_pback_sizeE
- .section .rdata$_ZNSt15basic_streambufIcSt11char_traitsIcEE13_S_pback_sizeE,""
- .linkonce same_size
- .align 4
- __ZNSt15basic_streambufIcSt11char_traitsIcEE13_S_pback_sizeE:
- .long 1
- .globl __ZTV1B
- .section .rdata$_ZTV1B,""
- .linkonce same_size
- .align 8
- __ZTV1B:
- .long 0
- .long __ZTI1B
- .long __ZN1B4sizeEv
- .section .text$_ZN1AC2Ev,"x"
- .linkonce discard
- .align 2
- .globl __ZN1AC2Ev
- .def __ZN1AC2Ev; .scl 2; .type 32; .endef
- __ZN1AC2Ev:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- movl 8(%ebp), %eax
- movl $__ZTV1A+8, (%eax)
- movl 8(%ebp), %eax
- movl $10, 4(%eax)
- movl 8(%ebp), %eax
- movl 4(%eax), %eax
- movl %eax, 4(%esp)
- movl $__ZSt4cout, (%esp)
- call __ZNSolsEi
- movl $__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, 4(%esp)
- movl %eax, (%esp)
- call __ZNSolsEPFRSoS_E
- movl 8(%ebp), %eax
- movl %eax, (%esp)
- call __ZN1A4sizeEv
- leave
- ret
- .section .text$_ZN1B4sizeEv,"x"
- .linkonce discard
- .align 2
- .globl __ZN1B4sizeEv
- .def __ZN1B4sizeEv; .scl 2; .type 32; .endef
- __ZN1B4sizeEv:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- movl $12, 4(%esp)
- movl $__ZSt4cout, (%esp)
- call __ZNSolsEj
- movl $__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, 4(%esp)
- movl %eax, (%esp)
- call __ZNSolsEPFRSoS_E
- leave
- ret
- .globl __ZTI1B
- .section .rdata$_ZTI1B,""
- .linkonce same_size
- .align 4
- __ZTI1B:
- .long __ZTVN10__cxxabiv120__si_class_type_infoE+8
- .long __ZTS1B
- .long __ZTI1A
- .globl __ZTS1B
- .section .rdata$_ZTS1B,""
- .linkonce same_size
- __ZTS1B:
- .ascii "1B\0"
- .globl __ZTV1A
- .section .rdata$_ZTV1A,""
- .linkonce same_size
- .align 8
- __ZTV1A:
- .long 0
- .long __ZTI1A
- .long __ZN1A4sizeEv
- .section .text$_ZN1A4sizeEv,"x"
- .linkonce discard
- .align 2
- .globl __ZN1A4sizeEv
- .def __ZN1A4sizeEv; .scl 2; .type 32; .endef
- __ZN1A4sizeEv:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- movl $8, 4(%esp)
- movl $__ZSt4cout, (%esp)
- call __ZNSolsEj
- movl $__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, 4(%esp)
- movl %eax, (%esp)
- call __ZNSolsEPFRSoS_E
- leave
- ret
- .globl __ZTI1A
- .section .rdata$_ZTI1A,""
- .linkonce same_size
- .align 4
- __ZTI1A:
- .long __ZTVN10__cxxabiv117__class_type_infoE+8
- .long __ZTS1A
- .globl __ZTS1A
- .section .rdata$_ZTS1A,""
- .linkonce same_size
- __ZTS1A:
- .ascii "1A\0"
- .text
- .align 2
- .def __GLOBAL__I_main; .scl 3; .type 32; .endef
- __GLOBAL__I_main:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- movl $65535, 4(%esp)
- movl $1, (%esp)
- call __Z41__static_initialization_and_destruction_0ii
- leave
- ret
- .section .ctors,"w"
- .align 4
- .long __GLOBAL__I_main
- .text
- .align 2
- .def __GLOBAL__D_main; .scl 3; .type 32; .endef
- __GLOBAL__D_main:
- pushl %ebp
- movl %esp, %ebp
- subl $8, %esp
- movl $65535, 4(%esp)
- movl $0, (%esp)
- call __Z41__static_initialization_and_destruction_0ii
- leave
- ret
- .section .dtors,"w"
- .align 4
- .long __GLOBAL__D_main
- .def __ZNSt8ios_base4InitD1Ev; .scl 3; .type 32; .endef
- .def _system; .scl 3; .type 32; .endef
- .def __ZN1BC1Ev; .scl 3; .type 32; .endef
- .def __ZN1B4sizeEv; .scl 3; .type 32; .endef
- .def __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc; .scl 3; .type 32; .endef
- .def __ZN1AC2Ev; .scl 3; .type 32; .endef
- .def __ZNSolsEj; .scl 3; .type 32; .endef
- .def __ZN1A4sizeEv; .scl 3; .type 32; .endef
- .def __ZNSolsEPFRSoS_E; .scl 3; .type 32; .endef
- .def __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_; .scl 3; .type 32; .endef
- .def __ZNSolsEi; .scl 3; .type 32; .endef
- .def __ZNSt8ios_base4InitC1Ev; .scl 3; .type 32; .endef
复制代码
上面是由下面的程序的来的
- #include <iostream>;
- using namespace std;
- class A
- {
- public:
- int i;
- A():i(10){cout<<i<<endl;size();}
- virtual void size(){cout<<sizeof(A)<<endl;}
- };
- class B :public A
- {
- public:
- int j;
- B():A(),j(20){cout<<i<<","<<j<<endl;size();}
- virtual void size(){cout<<sizeof(B)<<endl;}
- };
- int main()
- {
- B b;
- system("pause");
- }
复制代码
哪位牛人给分析一下vptr是在哪里初始化的?? |
|