Re: Interfaces and templates

2019-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 09/20/2019 12:02 PM, JN wrote: > import std.stdio; > > interface IWriter > { > void write(U)(U x); > } > > class Foo : IWriter > { > void write(U)(U x, int y) > { > writeln(x); > } > } > > > > void main() > { > } > > Does this code make sense? No. Function template

Re: Interfaces and templates

2019-09-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 20 September 2019 at 19:02:11 UTC, JN wrote: If so, why doesn't it throw an error about unimplemented write (or incorrectly implemented) method? because you never used it. templates don't get checked by the compiler until they are used...

Interfaces and templates

2019-09-20 Thread JN via Digitalmars-d-learn
import std.stdio; interface IWriter { void write(U)(U x); } class Foo : IWriter { void write(U)(U x, int y) { writeln(x); } } void main() { } Does this code make sense? If so, why doesn't it throw an error about unimplemented write (or incorrectly implemented) method