Search code examples
c++objective-cdynamic-bindingdynamic-dispatch

O'Reilly's "Objective-C Pocket Reference" claims C++ doesn't support Dynamic Dispatch, is this true?


On page 4, it says:

Objective-C decides dynamically--at run-time--what code will handle a message by searching the receiver's class and parent classes. (The Objective-C runtime caches the search results for better performance.) By contrast, a C++ compiler constructs a dispatch table statically -- at compile time.

I've read a lot on StackOverflow and Wikipedia, and suffice it to say I'm utterly confused as to whether or not C++ supports Dynamic Dispatch (which some say is an implementation of Dynamic Binding).

Anyone able to clear up the difference between Dynamic Dispatch, Dynamic Binding, and whether or not C++ supports one of or both of those? I'm not a C++ or Objective-C expert, I'm coming from a Java, Python and PHP world.


Solution

  • The dynamic dispatch referred to in this book is probably a different dynamic dispatch typically referred to in thr C++ context:

    • C++ support dynamic dispatch in the form of virtual functions. The corresponding names and parameters are indeed known at compile time although the actual finction called depends on the dynamic type of the object.
    • I'm not an Objective C expert but my understanding is that you can dynamically add functions to individual objects at run-time which are looked up when being called. C++ doesn't support this sort of dynamic dispatch.