Search code examples
c++virtual-functionsoverridingdynamic-bindingstatic-binding

Binding type for a non-overriden virtual function


Consider the case where a virtual function in base class is not overriden in the derived class. Then using a base class pointer to a derived class objectthe virtual function is invoked.

I understand that the function invocation will be resolved to the function in the base class during compile-time.

Question

Since the function is not overriden in the derived class, will the function call be bound to the function implementation during compile-time or will it still delay the binding until run-time?


Solution

  • Most likely it will be resolved at compile time.
    Most of the modern day compilers are smart enough to resolve dynamic dispatch at compilation time if there is enough credible information for them to decide so.
    In this case since no overriding function is provided in the Derived class a smart compiler should be able to resolve the function call at compilation time statically.