|
|
发表于 2006-3-12 02:08:00
|
显示全部楼层
Re:C++里的多继承~不明白~
cout << "CB::m_a=" <<CB::m_a << endl;
0043E5D3 push offset std::endl (43A7DAh)
0043E5D8 mov eax,dword ptr [this] A
0043E5DB mov ecx,dword ptr [eax] B
0043E5DD push ecx
0043E5DE push offset string "CB::m_a=" (4B4240h)
0043E5E3 push offset std::cout (4CA068h)
0043E5E8 call std: perator<<<std::char_traits<char> > (43B211h)
0043E5ED add esp,8
0043E5F0 mov ecx,eax
0043E5F2 call std::basic_ostream<char,std::char_traits<char> >::operator<< (43A9D8h)
0043E5F7 mov ecx,eax
0043E5F9 call std::basic_ostream<char,std::char_traits<char> >::operator<< (43B24Dh)
cout << "CC::m_a=" << CC::m_a << endl;
0043E5FE push offset std::endl (43A7DAh)
0043E603 mov eax,dword ptr [this] C
0043E606 mov ecx,dword ptr [eax+4] D
0043E609 push ecx
0043E60A push offset string "CC::m_a=" (4B4234h)
0043E60F push offset std::cout (4CA068h)
0043E614 call std::operator<<<std::char_traits<char> > (43B211h)
0043E619 add esp,8
0043E61C mov ecx,eax
0043E61E call std::basic_ostream<char,std::char_traits<char> >::operator<< (43A9D8h)
0043E623 mov ecx,eax
0043E625 call std::basic_ostream<char,std::char_traits<char> >::operator<< (43B24Dh)
cout << "CA::m_a=" << CA::m_a << endl;
0043E62A push offset std::endl (43A7DAh)
0043E62F mov eax,dword ptr [this] E
0043E632 mov ecx,dword ptr [eax] F
0043E634 push ecx
0043E635 push offset string "CA::m_a=" (4B4228h)
0043E63A push offset std::cout (4CA068h)
0043E63F call std::operator<<<std::char_traits<char> > (43B211h)
0043E644 add esp,8
0043E647 mov ecx,eax
0043E649 call std::basic_ostream<char,std::char_traits<char> >::operator<< (43A9D8h)
0043E64E mov ecx,eax
0043E650 call std::basic_ostream<char,std::char_traits<char> >::operator<< (43B24Dh)
以上是我用vs2005EE反汇编的结果,当然只是显示Display函数中的内容,我在程序中标定了六处地方,分别用ABCDEF表示。A中将this地址,也就是CD的地址赋给eax,然后将eax中的内容送到ecx中然后输出,从堆砌的结果来看,应该是先堆砌CB(先继承CB),所以m_a位于偏移量为0的位置上,即this + 0的地址,然后再输出其值;D中是将this + 4的地址中的内容给了ecx后输出,4个字节刚好是一个int的大小,也就是m_a的大小,从堆砌上来看,CC中继承的m_a在DD的this + 4的位置上,符合堆砌的结果。最后,E、F跟输出CB时一致,说明编译器认为CA::m_a的地址和CB::m_a的地址一致。因为类中没有虚函数,所以没有虚函数的指针表,变量便按照继承的顺序堆砌。以上是我的理解,请大家指正。 |
|