dynamic_cast
is generally used when we have a base class pointer and want to downcast it to a derived class. For instance,
class A
{
public:
virtual void foo();
};
class B : public A
{
public:
void foo();
};
main()
{
A* a = new B();
B* b = dynamic_cast<B*> (a);
}
But, the same can also be accomplised by using C-style
cast:
B* b = (B*)a;
So, my question is what are the circumstances/cases where it becomes completely necessary to use this operator i.e. there is no other choice?