static_cast vs dynamic_cast

前端 未结 3 1952
死守一世寂寞
死守一世寂寞 2021-02-05 17:43

Suppose I\'m given a C++ library full of inheritance. I\'m given a Base* in a function when I know that it is actually pointing to a Derived object and

3条回答
  •  被撕碎了的回忆
    2021-02-05 18:01

    Use static_cast. If you know that your Base* points to a Derived, then use static_cast. dynamic_cast is useful for when it might point to a derived.

提交回复
热议问题