Is there any purpose to using dynamic_cast
when the return value isn't checked for NULL
? If I'm looking at a code base, and the null check it omitted from the return value, might it have been just as well to use static_cast
?
A *a = dynamic_cast<A *>(b);
foo(*a); //might as well have used a static_cast
I've read all that Google affords on the matter, and it seems that checking for null is the only reason, but I've yet to see anyone come out and say "dynamic_cast without a null check is a waste of cycles (and a possible bloating of the code with RTTI)."
Edit: It's been put to me that if there's virtual inheritance between the types, that static_cast
would fail where dynamic_cast
would not. In my case, that's not the case.