(minor) You don't need the conditional -- dynamic_cast<...>(NULL) == NULL.