Dynamic Binding in C++

Arjun picture Arjun · Apr 10, 2009 · Viewed 10.5k times · Source

I need some clarification on dynamic binding in C++ .I'm confused about the following:

  1. In C you can have an array of function pointers & assign different functions of the same signature & call them based on the index; is this Dynamic binding?

  2. In C++ you can have an array of base class pointers but you can call different functions of the derived class, by assigning the derived class objects addresses to a base-class array of pointers & by using virtual functions, Is this Dynamic Binding?

  3. Which term is correct - Dynamic binding or Link-Time Binding?

Answer

JaredPar picture JaredPar · Apr 10, 2009

Answers

  1. No. This is much closer to dynamic dispatch than dynamic binding. Dynamic binding refers to the way in which a named method is bound at runtime. There is no name here.
  2. Yes. If the methods are virtual then this is the definition of dynamic binding. The name is known at compile time but the method called cannot be determined without knowing the runtime object type
  3. I'm not sure what you mean here. Dynamic binding is the more idiomatic term.