If I have this situation in C++ project:
- 1 base class ‘Base’ containing only pure virtual functions
- 1 class ‘Derived’, which is the only class which inherits (public) from ‘Base’
Will the compiler generate a VTABLE?
It seems there would be no need because the project only contains 1 class to which a Base* pointer could possibly point (Derived), so this could be resolved compile time for all cases.
This is interesting if you want to do dependency injection for unit testing but don’t want to incur the VTABLE lookup costs in production code.
I don’t have hard data, but I have good reasons to say no, it won’t turn virtual calls into static ones.
virtual. Review your design. If you need some polymorphism but not the full power of virtual, the curiously recurring template pattern may help.