opDispatch doesn't play nice with inheritance

Ali Çehreli acehreli at yahoo.com
Thu Nov 15 19:01:45 UTC 2018


On 11/15/2018 09:14 AM, Carl Sturtivant wrote:

 > opDispatch is special in that it allows for functions to be added to a
 > class or struct when undefined overtly but used elsewhere but it seems
 > those functions sadly are final.
 >
 > Can anything useful be done to remedy the situation?

For the compiler to be able to make all opDispatch instantiations 
virtual, it would have to first see all calls that generate opDispatch 
instantiations. (Impossible in the presence of separate compilation.)

Only then the compiler would know how large the vtbl of the base class 
should be and what member functions of the derived class are overrides 
of those virtual functions.

I think it would be confusing as well; a function suddenly becomes 
virtual just because someone else made a call on the base class interface.

Ali



More information about the Digitalmars-d-learn mailing list