From Jason Turner
Watch on YouTube

Summary

In this episode, Jason explores the concept of multiple dispatch (also known as multimethods), which allows function calls to be dynamically dispatched based on the runtime types of multiple arguments. He contrasts this with single dispatch polymorphism (using virtual functions), where dispatching is based only on the type of the object a method is called on. The episode demonstrates two C++ approaches to implement multiple dispatch: a manual approach using dynamic_cast with inheritance hierarchies, which is error-prone and verbose, and a more elegant approach using std::variant and std::visit that can handle multiple types without heap allocations.

Resources

Tags