3 ms·
Since there was no answer, and no concrete example where inheritance was needed, I'll just provide one possible solution: you can store a function pointer that
by kubb 5y ago
Since there was no answer, and no concrete example where inheritance was needed, I'll just provide one possible solution: you can store a function pointer that implements the desired varying functionality as a part of the struct whose implementation you want to slightly change. That function can accept self as the first argument like any method.
Performance-wise this is the same as a vtable generated by c++ and doesn't require creating more entities.