I took a hit in C ++. I ended up with something that works, but it's a macrocycle: https://github.com/wkaras/c-plus-plus-misc/tree/master/IFACE . An interface is two pointers, one for object data elements, and the other the equivalent of a virtual table (a structure of pointers to thunk functions that invoke member functions). These tables (unfortunately) are generated at runtime. Converting from an interface to a sub-interface requires a search in order of unordered_map, so on average this is O (1) complexity. Compared to converting a pointer of a derived class / reference to one to the base class, which is O (1) the worst.
It is not very useful, but it shows that interfaces can be (purely) added in C ++ with relatively little effort. There are times when interfaces are better than OO inheritance, and a cow is good from the barn, as it tries to keep C ++ small.
source share