C++: Calling the virtual function of the derived class

前端 未结 3 1996
陌清茗
陌清茗 2021-01-13 11:41

Suppose I have a class with a virtual function and a derived class that implements the virtual function in a different way. Suppose I also have a vector of the base class u

3条回答
  •  再見小時候
    2021-01-13 12:06

    The class that you are actually calling is not a class of Bar, but instead a class of Foo. What you are doing at foo_vector [0] = bar; is a call of the implicit operator= which is doing its best to make something smart happen. The memory space is still the size of a Foo though, so it can't ever be a Bar.

提交回复
热议问题