1、c++类方法继承与重载内部实现
2、源代码
#include <iostream>
using namespace std ;
class supper
{
protected :
virtual void doSome()
{
cout << "supper class method doSome " << endl ;
}
virtual void doOther()
{
cout << "supper class method doOther " << endl ;
}
} ;
class sub : public supper
{
public:
using supper:: doSome ;
virtual void doSome(int i )
{
cout << "sub class method doSome " << endl ;
}
using supper::doOther ;
virtual void doOther(int other)
{
cout << "sub class method doOther" << endl ;
}
}
;
int main()
{
sub s ;
s.doSome() ;
s.doOther() ;
}
3、目标码
47 {
0x0000000000400892 <+0>: push %rbp
0x0000000000400893 <+1>: mov %rsp,%rbp
0x0000000000400896 <+4>: sub $0x10,%rsp
48 sub s ;
=> 0x000000000040089a <+8>: mov $0x400ae0,%eax
0x000000000040089f <+13>: mov %rax,-0x8(%rbp)
49 s.doSome() ;
0x00000000004008a3 <+17>: mov -0x8(%rbp),%rax
0x00000000004008a7 <+21>: mov (%rax),%rdx
0x00000000004008aa <+24>: lea -0x8(%rbp),%rax
0x00000000004008ae <+28>: mov %rax,%rdi
0x00000000004008b1 <+31>: callq *%rdx
50 s.doOther() ;
0x00000000004008b3 <+33>: mov -0x8(%rbp),%rax
0x00000000004008b7 <+37>: add $0x8,%rax
0x00000000004008bb <+41>: mov (%rax),%rdx
0x00000000004008be <+44>: lea -0x8(%rbp),%rax
0x00000000004008c2 <+48>: mov %rax,%rdi
0x00000000004008c5 <+51>: callq *%rdx
51
52
53 }
0x00000000004008c7 <+53>: mov $0x0,%eax
0x00000000004008cc <+58>: leaveq
0x00000000004008cd <+59>: retq
4、目标码结构

5、目标结构分析
(gdb) p &s
$9 = (sub *) 0x7fffffffe2d8
(gdb) x /xg 0x7fffffffe2d8
0x7fffffffe2d8: **0x0000000000400ae0**
(gdb) x /xg 0x0000000000400ae0
0x400ae0 <_ZTV3sub+16>: 0x0000000000400922
(gdb) x /s **0x0000000000400922**
0x400922 <supper::doSome()>: "UH\211\345H\203\354\020H\211}\370\276e\n@"
(gdb) x /xg 0x0000000000400ae0 + 8
0x400ae8 <_ZTV3sub+24>: 0x000000000040094e
(gdb) x /s **0x000000000040094e**
0x40094e <supper::doOther()>: "UH\211\345H\203\354\020H\211}\370\276\201\n@"