When is static cast safe when you are using multiple inheritance?

前端 未结 6 609
眼角桃花
眼角桃花 2020-12-10 12:26

I found myself in a situation where I know what type something is. The Type is one of three (or more) levels of inheritance. I call factory which returns B* how

6条回答
  •  甜味超标
    2020-12-10 13:17

    If Derived has Base as a public (or otherwise accessible) base class, and d is of type Derived*, then static_cast(d) is an upcast.

    This is always technically safe.

    And generally unnecessary, except for cases where you have hiding (shadowing) of method.

    Cheers & hth.,

提交回复
热议问题