前篇:http://blog.csdn.net/pathuang68/archive/2009/04/23/4102002.aspx

对象内存布局 (5)的代码中,在Derived类中覆盖Base1中声明的vfBase1_1(),其他代码不变。修改后的Derived的定义如下:

class Derived : public Base1, public Base2, public Base3

{

public:

int m_derived;

inline virtual void fd()

{

cout << "This is in Derived::fd()" << endl;

}

inline void vfBase1_1()

{

cout << "This is in Derived::vfBase1_1()" << endl;

}

};

运行结果如下:

对象内存布局 (7)

Derived对象值memory layout图解如下:

对象内存布局 (7)

我们可以看到,在Derived中overriden的虚函数Derived::vfBase1_1排在第一个虚函数表的第一位。虚函数Base::vfBase1_1()由于已经被overridden,所以在Derived对象的虚函数表中不再出现。

后篇:http://blog.csdn.net/pathuang68/archive/2009/04/23/4102006.aspx

相关文章:

  • 2021-04-18
  • 2021-08-13
  • 2021-10-15
  • 2022-01-09
  • 2021-07-04
  • 2021-05-18
猜你喜欢
  • 2021-09-09
  • 2021-08-01
  • 2021-05-25
  • 2021-07-08
相关资源
相似解决方案