Mix struct types in the same array
tirithen
tirithen at gmail.com
Thu Dec 19 18:21:32 UTC 2019
On Thursday, 19 December 2019 at 00:00:56 UTC, Paul Backus wrote:
>
> interface Action
> {
> void applyTo(ref User); <-- change to applyTo(T)(ref T)
> }
>
> class ActionAdapter(T) : Action
> {
> T payload;
>
> this(T payload)
> {
> this.payload = payload;
> }
>
> override void applyTo(ref User user) <-- change to
> applyTo(U)(ref U entity)
> {
> payload.applyTo(user);
> }
> }
Is there a way I can make the example a bit more generic even by
replacing the User type with a template. I tried:
applyTo(ref User); <-- applyTo(T)(ref T)
applyTo(ref User user) <-- applyTo(U)(ref U entity)
It compiled but crashed with:
Linking...
/usr/bin/ld:
.dub/build/application-debug-linux.posix-x86_64-dmd_2089-4CFAD9B3CA5E5532C5E0608F9332C781/tryit.o: in function `_Dmain':
.....tryit/source/app.d:55: undefined reference to
`_D5plant5tryit3app5Event__T7applyToTSQBjQBgQBd4UserZQzMFKQvZv'
collect2: fel: ld returnerade avslutningsstatus 1
I'm still a bit new to this language so need to practice
templates more, but I find D overall nice.
More information about the Digitalmars-d-learn
mailing list