Dynamic dispatch is used by the compiler in C++ if all of the following are true:
- A reference variable p (actual pointer or a reference to a class) is used to invoke a method, f, AND
- The variable p is a pointer or reference to some class X, AND
- The function f is (effectively) virtual in class X.
Otherwise, static dispatch is used by the compiler, which means that the implementation of f in the class X from the declaration of p is used.