Double Dispatch in C++

Double Dispatch in C++ is a mechanism that dispatches a function call to different concrete functions depending on the runtime types of two objects involved in the call. In more simple words, its function calling using two different virtual tables of respective two objects. I know this sounds cryptic, but don't worry I will come to double dispatch solution after trying most of the naive solution so that you will come away with the full understanding of concept without having needless confusions.

Motivation

  • At first, a pointer to a base class made sense; you didn't need to know the actual derived class. So you decided to expose a single collection of base class pointers to your clients like so:
C++




x



1
struct Animal {    
2
    virtual const char *name() = 0;
3
};
4

           
5
using AnimalList = vector<Animal*>;



To C, or Not To C: How Can We Best Teach the Coders of the Future?

Photo credit by Unsplash/Good Free Photos

HackerRank is known for its invaluable research into the lives of those who make the tech world go round, and this year’s Women in Tech Report is no exception. Filled with numerous important insights into the skills and motivations of the youngest female developers entering the workforce, it is an absolute must-read for any hiring manager looking to bring on the best and brightest of this uniquely savvy generation.