2 ms·
> If your class never needs a runtime virtual call because all virtual calls were monomorphisable, why would it still include a virtual table? What’s the point?
by jcelerier 5y ago
> If your class never needs a runtime virtual call because all virtual calls were monomorphisable, why would it still include a virtual table? What’s the point?
if that was not the case, it would mean that the size of the type would vary, which would break a lot of expectations.
Imagine the following:
class obj { virtual int space_used() { return sizeof(obj); } };
class sub1 : obj { int space_used() override { return sizeof(sub1); } };
it would be very normal for someone to call `space_used();` at some point, and use that size at another point (with a different instance), for instance for allocation ; if that size was to change because that instance was "optimized" by the compiler, that could wreak havoc.
- chrisseaton 5y agoAh I assumed it knew about all classes before it started running compile-time code.