Difference in behavior while using dynamic_cast with reference and pointers

后端 未结 4 1025
小鲜肉
小鲜肉 2020-11-29 04:23

I was checking the behavior of dynamic_cast and found that when it fails, std::bad_cast exception is thrown only if the destination is a reference type. If the destination i

4条回答
  •  无人及你
    2020-11-29 05:02

    Yes, 5.2.7/9

    The value of a failed cast to pointer type is the null pointer value of the required result type. A failed cast to reference type throws bad_cast (18.5.2).

提交回复
热议问题