|
|
|
|
|
by o11c
906 days ago
|
|
Hmm, I don't have much to disagree with for this link, unlike many things from that site. One minor point - the method implementations should not be `static`, so that you can support further subclassing and reuse the base class implementations. Note that to support both virtual and non-virtual method binding, the dispatcher also needs to be exported (with the same signature). This is already the case in the linked code but a point isn't made of it; it can be tempting to abuse `inline` but remember that is primarily about visibility [1]. It also doesn't mention how to implement `dynamic_cast` (practically mandatory for multimethod-like things), which can be quite tricky, especially in the multiple-inheritance case and/or when you don't know all the subclasses ahead of time and/or when you have classes used in across shared libraries. There are cases where you really do need multiple vtables. Virtual inheritance, despite its uses, is probably a mistake so it's fine that it ignores that. [1]: https://stackoverflow.com/a/51229603/1405588 |
|