Now I'm reading Scott Myers' Effective C ++. Edification! Clause 2 mentions that dynamic_cast can be used not only for downcasts, but also for sibling. Can someone provide a (reasonably) laid-back example of its use for brothers and sisters? This stupid test prints 0 as it should, but I cannot imagine any application for such conversions.
#include <iostream> using namespace std; class B { public: virtual ~B() {} }; class D1 : public B {}; class D2 : public B {}; int main() { B* pb = new D1; D2* pd2 = dynamic_cast<D2*>(pb); cout << pd2 << endl; }
c ++ inheritance dynamic-cast siblings
sigil
source share