3 ms·
Can you imagine a non-inheritance solution to this problem? If you used this way of solving things your whole life then I understand that changing paradigms is
by kubb 5y ago
Can you imagine a non-inheritance solution to this problem? If you used this way of solving things your whole life then I understand that changing paradigms is a challenge.
- kubb 5y agoSince 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.