Daily bit(e) of C++ | Type erasure: void*
Daily bit(e) of C++ #319, Type erasure imitating dynamic dispatch using void* and function pointers.
One downside of relying on dynamic dispatch is the intrusive instrumentation overhead.
Types with virtual methods store a pointer to the virtual function table and are disqualified from many optimizations and conveniences (trivial copyability, aggregate initialization).
Fortunately, the same logic can be manually re-implemented externally using void* and function pointers.
Could you explain why this is better than virtual methods? In the end you’re still referencing the implementation through a pointer, hence introducing the same level of indirection