why there are two virtual destructor in the virtual table and where is address of the non-virtual function (gcc4.6.3)

后端 未结 2 1182
小蘑菇
小蘑菇 2021-02-01 16:51

I implemented a simple test to check the memory rank of Derived class, so I find there are two virtual destructor address in the virtual table of Derive class. Can someone expla

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 16:52

    1. Why are there two?

    This must be specific case to your compiler, I did the same in g++ and result only one destructor call only.

    ~Derive
    ~Base2
    ~Base1
    

    link to results: https://ideone.com/vzZggh

    1. Where is the address of the non-virtual member function?

    yes, for non-virtual member functions you need to go to base class.

    Non-virtual function address does not exist in the memory of the derived class.

提交回复
热议问题