C++ – In C++ if a member function is virtual when can static binding be used

bindingc++static

In C++ when can a virtual function use static binding? If it is being accessed through a pointer, accessed directly, or never?

Best Solution

When a virtual method is called through a pointer or reference, dynamic binding is used. Any other time, compile-time binding is used. Ex:

class C;

void Foo(C* a, C& b, C c) {
  a->foo();  // dynamic
  b.foo();  // dynamic
  c.foo();  // static (compile-time)
}