Dynamic templated virtuals - I still often want them

Steven Schveighoffer schveiguy at gmail.com
Tue Jul 28 21:09:51 UTC 2020


On 7/28/20 5:01 PM, Alexandru Ermicioi wrote:
> On Thursday, 23 July 2020 at 02:38:27 UTC, Adam D. Ruppe wrote:
>>
>> But imagine if `serialize` actually got a virtual table entry, just 
>> like if it wasn't a template at all, but each child class 
>> automatically got an instance of it made for itself.
> 
> 
> That will fail for at least one use case:
> Consider class A that has templated virtual method do. It lives in 
> library X. Then we have class B : A that is in library Y. Now 
> application U has variable of type A that contains type B. At some point 
> U calls 'do' with an int. How should compiler proceed with such 
> situation given Y is available only in compiled version?

It should work. The idea is that the derived type generates the template 
code and stores it in the vtable. It's not much different from the 
solution Max Samukha posted, except the compiler should do it instead of 
the user, and it's put in the vtable instead of the instance.

So it doesn't matter where the code is stored, it is already concrete 
and part of the vtable.

-Steve


More information about the Digitalmars-d mailing list