Virtual Functions Object Slicing

后端 未结 2 1613
-上瘾入骨i
-上瘾入骨i 2020-12-19 11:53

My question is with reference to this question which explains how virtual functions work in case of object slicing which end up calling base class virtual function and Wikip

2条回答
  •  无人及你
    2020-12-19 12:07

    A oA = *ptr1;
    

    This copies any member variables into a new A object. The vtable pointer is not a normal member variable and is not copied. Thus any subsequent virtual functions called against this object will act as if it is an A object, because it is an A object.

提交回复
热议问题