virtual function declared non-virtual in a derived class

后端 未结 5 2404
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 12:56

If a function is declared non-virtual in a derived class when the base class function was virutal, why does it invoke a vtable lookup on calling the function on its pointer? The

5条回答
  •  礼貌的吻别
    2021-02-19 13:37

    You cannot make a function non-virtual, so it will stay virtual and a call to the function is in general also virtual. Of course, there are situations where the compiler will be able to optimize this and do a direct call, but apparantly not in your scenario.

提交回复
热议问题