This is a question regarding how Multiple Dispatch works.
Suppose that we have a type hierarchy like this:
Drawable -> Shape -> Polygon -> Rectangle
And there are three functions (This is a pseudo-code):
void func(Rectangle*, Drawable*, Drawable*) ...
void func(Rectangle*, Rectangle*, Drawable*) ...
void func(Polygon*, Rectangle*, Rectangle*) ...
And suppose that this is a piece of code:
Drawable* x = create_rectangle();
Drawable* y = create_rectangle();
Drawable* z = create_rectangle();
Obviously types of x,y,z
are all Drawable
but they contain instances of a Rectangle
. Which function will be called if I write: func(x, y, z)
?
We don't have any function which matches exact types of x, y and z
so what happens in this case?