This is my code. I just want to have a look at the memory layout of virtual inherit.
#include<iostream>
using namespace std;
class A{
private:
int a;
public:
virtual void print() const{
cout << a << endl;
}
};
class B:public virtual A{
private:
int b;
public:
void print() const{
cout << b << endl;
}
};
int main(){
A a;
B b;
return 0;
}
Then in gdb, I used
p a
p b
The output is
(gdb) p a
$1 = {
_vptr.A = 0x400b40 <vtable for A+16>,
a = 0
}
(gdb) p b
$2 = {
<A> = {
_vptr.A = 0x400b18 <vtable for B+56>,
a = 4196384
},
members of B:
_vptr.B = 0x400af8 <vtable for B+24>,
b = 0
}
(gdb)
I know the meaning of _vptr.A and _vptr.B but I don't understand the what does vtable for B+24 or A+16 mean.
Thanks for the answer!