5.2.7/7 says something along the lines of:
If
Tis "pointer tocv void", the result is a pointer to the most derived class pointed to byx.
What is a good application of this syntax? When should dynamic_cast<void*> be used?
5.2.7/7 says something along the lines of:
If
Tis "pointer tocv void", the result is a pointer to the most derived class pointed to byx.
What is a good application of this syntax? When should dynamic_cast<void*> be used?
One common reason is to figure out whether two interfaces IA* and IB* are in fact pointers to the same underlying object. If you need that, use the cast.
IIRC, it's even possible in case of Multiple Inheritance with a repeated non-virtual base to have two IA* pointers which compare unequal, yet point to the same object - because they point to two different IA subobjects.
When you have something like:
template<typename X, typename Y>
bool operator==(const X* px, const Y* py) {
return dynamic_cast<void*>(px) == dynamic_cast<void*>(py);
}