Cast to a Child

前端 未结 4 1802
无人及你
无人及你 2021-01-23 07:47

What I\'m actually trying to do is cast a constructed moneypunct to the punct_facet in this question without writing a copy constructor as in this answ

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-23 08:20

    It is not legal to assign address of base object to pointer of derived class.

    If you want to call virtual function in derived class, you have to instantiate an object of derived class and call it thru this object, or pointer (of which type might be base class) to this object.

    Virtual function tables in base and derived class are separated, so you cannot access virtual function of derived class thru an object of base class

提交回复
热议问题