Since disp() does not have access to any member of the class, it is basically the same as if it were declared in the global namespace, and not in the class, so there are no negative side effects to call it, even if the instance is not corresponds to the class.
What you do is lower the pointer of the base class to the pointer of the derived class, although it was not initialized as such. If disp() tried to access class members that were in D but not in B , you would probably encounter segfaults.
Bottom line: Do not use static_cast for downcasting unless you are sure that the pointer is actually pointing to an instance of the derived class. If you are not sure, you can use dynamic_cast , which fails in case of non-compliance (but there is RTTI overhead, so avoid it if you can).
dynamic_cast will return nullptr if the throw is incorrect or throw a std::bad_cast exception if it refers to links, so you know exactly why this happens, and not possible memory corruption errors.
source share