Does anybody know how Go manages to call the given function of the matching interface when it gets only a pointer to the struct? Like here, where label and button are otherwise unrelated structs but both have the same Paint function:
for _, painter := range []Painter{label, listBox, button1, button2} {
painter.Paint()
}
In C++, where inheritance is used, the virtual function pointer tables are maintained and the inherited class will have the function at the same index which makes calls of virtual functions slower than normal calls but the cost is still just an indexing of the table. However when there is no inheritance specification, the indexes can't be maintained, I presume. The easy solution is that calls are resolved using some string fingerprint lookup but that would make such calls really slow (compared to the C++).Then how do they do it?