Mix struct types in the same array
tirithen
tirithen at gmail.com
Fri Dec 20 12:08:46 UTC 2019
On Thursday, 19 December 2019 at 21:26:51 UTC, Paul Backus wrote:
>
> The reason this doesn't work is that interface methods are
> virtual, and virtual methods can't be templates. [1] If you
> want to have multiple kinds of entities, one option is to
> create an Entity interface and EntityAdapter(T) class using the
> same technique as above, and have your applyTo method accept an
> Entity as its argument. You can see an example of what that
> would look like at the following link:
>
> https://gist.github.com/pbackus/f61734804a627d379c7916f783ea7725#file-oop_version-d
>
> Another option is to forget about classes and interfaces and do
> everything with templates, using a library like sumtype [2].
> Here's a link to an example of what that would look like:
>
> https://gist.github.com/pbackus/f61734804a627d379c7916f783ea7725#file-template_version-d
Thanks for a good explanation around virtual methods and
templates as well as examples! Now I have plenty of good examples
to play around with. :)
More information about the Digitalmars-d-learn
mailing list