Difference in behavior while using dynamic_cast with reference and pointers

后端 未结 4 1011
小鲜肉
小鲜肉 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:01

    Yes, it is. Because dynamic_cast can't return NULL for a failed reference cast, an exception is the only way out.

    That is, a reference can't be NULL, so there is nothing suitable to return.

提交回复
热议问题