In C++, the T q = dynamic_cast<T>(p);
construction performs a runtime cast of a pointer p
to some other pointer type T
that must appear in the inheritance hierarchy of the dynamic type of *p
in order to succeed. That is all fine and well.
However, it is also possible to perform dynamic_cast<void*>(p)
, which will simply return a pointer to the "most derived object" (see 5.2.7::7 in C++11). I understand that this feature probably comes out for free in the implementation of the dynamic cast, but is it useful in practice? After all, its return type is at best void*
, so what good is this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…