Number of Virtual tables and Virtual Pointers in a C++ Program

后端 未结 6 422
清歌不尽
清歌不尽 2020-12-08 17:20

Let say we have below program:

class A
{     public:
      virtual fun(){};
};
class B:public A
{     public:
     virtual fun(){};
};
int main()
{
     A a1         


        
6条回答
  •  伪装坚强ぢ
    2020-12-08 17:47

    There will be 2 vtables, one for class A and one for class B. And there will be 3 vptrs, one in a1 and two in b1(one pointing to vtable of class A and other pointing to vtable of class B).

提交回复
热议问题