你可以使用gcc的-fdump-class-hierarchy
选项,它会给你vtable的信息,但是输出可能非常冗长而难以阅读。
例如,给出下面的琐碎类:
class Base {
public:
virtual int method() = 0;
};
class Derived : public Base {
public:
int method() {
return 10;
}
};
相关的输出是
Vtable for Base
Base::_ZTV4Base: 3u entries
0 (int (*)(...))0
8 (int (*)(...))(& _ZTI4Base)
16 (int (*)(...))__cxa_pure_virtual
Class Base
size=8 align=8
base size=8 base align=8
Base (0x7f14c308ccc0) 0 nearly-empty
vptr=((& Base::_ZTV4Base) + 16u)
Vtable for Derived
Derived::_ZTV7Derived: 3u entries
0 (int (*)(...))0
8 (int (*)(...))(& _ZTI7Derived)
16 (int (*)(...))Derived::method
Class Derived
size=8 align=8
base size=8 base align=8
Derived (0x7f14c2ee7208) 0 nearly-empty
vptr=((& Derived::_ZTV7Derived) + 16u)
Base (0x7f14c308cd20) 0 nearly-empty
primary-for Derived (0x7f14c2ee7208)
这应该给你一个想法,地址范围debuggng等
我对此不是100%,所以我不会将它作为答案发布,但它应该足以查看'((void *)this)-1'(指针长度* *之前*这个')得到一个指向实际函数的指针(0终止的?)指针数组。他们不会携带方法名称或任何东西,但这确实是所有的虚拟表格。 – Blindy
您是否使用Valgrind或任何类似的工具来分析您的代码? –
你怎么知道你最终在一个不同的功能?你在调试或输出一些东西吗? –