Defining and overriding methods of an abstract base class which must accept a template parameter

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 10 14:38:09 PDT 2016


On Sunday, 10 July 2016 at 21:27:14 UTC, pineapple wrote:
> On Sunday, 10 July 2016 at 21:20:34 UTC, Basile B. wrote:
>> The problem you encounter here is that templatized functions 
>> cannot be virtual. If you remove "abstract" and put an empty 
>> body than it works, but you lose the whole OOP thing, i.e you 
>> cannot call the most derived override from the base.
>
> Yeah, that was the first thing I tried, and it took me a while 
> and some measure of annoyance to realize the base method was 
> being called instead of the derived one.
>
> Surely there's some reasonable workaround?

AFAIK no. OOP and templates don't mix well as main paradigm. This 
doesn't mean that templates can't be used in OOP (eg as template 
param for a class of for some helpers used in virtual function) 
but you see that one can break the other.


More information about the Digitalmars-d-learn mailing list