根据编译器的不同,虚拟继承的实现方式也不同。
1)是的,vc和gcc都使用vTable指针。但vc还有另一个指针ref作为虚拟基指针。
2) 对于经典的虚拟继承,如 Left < Top;右 < 上;Bottom < Left and Right 堆栈应该是这样的:
Left.vptr // -> to its vtable
Left::element_in_left
Right.vptr
Right::element_in_right
Bottom::element_in_bottom
Top::element_in_top
Run Code Online (Sandbox Code Playgroud)
程序使用vptr来查找vtable,对于gcc来说,viable中有一个虚拟基址偏移值。vptr + 基址偏移量将给出父地址。
3)我不知道你的意思是什么。在 C++ 编译器中可以采用不同的方法来实现它。其他语言也有自己的绑定函数的方法。
| 归档时间: |
|
| 查看次数: |
1078 次 |
| 最近记录: |