class Base {
public:
virtual ~Base() {}
// ...
};
class Derived : public Base {
// ...
};
"Typical use":
void foo(Derived*);
void f(Base* pb)
{
if (Derived* pd = dynamic_cast<Derived*>(pb)) {
foo(pd);
}
}
"Above quote":
void bar(Base*);
void f(Derived* pd)
{
Base* pb = dynamic_cast<Base*>(pd); // the dynamic_cast is useless here
// because a Derived IS-A Base, always
bar(pb); // Note: could as well call directly bar(pd); (implicit conversion)
}