dynamic_cast 的作用() the role of cynamic_cast

Posted diamondDemand

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dynamic_cast 的作用() the role of cynamic_cast相关的知识,希望对你有一定的参考价值。

cast a base calss pointer (or reference) to the inheritance class pointer, dynamic_cast will be based on the base class pointer is really pointing to the inheritance class pointer to do the appropriate treatment

将一个基类对象指针(或引用)cast到继承类指针,dynamic_cast会根据基类指针是否真正指向继承类指针来做相应处理

the dynamic_cast operator can determine the actual type at execution time. if the downcast is safe(that is, if the base class pointer or reference does point to a derived class object or reference does point to a derived class object)this operator will return the appropriate converted pointer. if downcast is unsafe, the operator will return a null pointer(that is, the base class pointer or reference does not point to a derived class object)

dynamic_cast运算符可以在执行期决定真正的类型。如果 downcast 是安全的(也就说,如果基类指针或者引用确实指向一个派生类对象)这个运算符会传回适当转型过的指针。如果 downcast 不安全,这个运算符会传回空指针(也就是说,基类指针或者引用没有指向一个派生类对象)。

以上是关于dynamic_cast 的作用() the role of cynamic_cast的主要内容,如果未能解决你的问题,请参考以下文章

dynamic_cast 用法

dynamic_cast

为啥受保护的继承会导致 dynamic_cast 失败?

dynamic_cast用法

dynamic_cast, RTTI, 整理

来自“void *”的dynamic_cast