digitalmars.D - InterfaceTemplates
- =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= (28/28) Jun 12 2004 It wasn't mentioned in the docs, but I had a slight inkling that it
- The Dr ... who? (7/35) Jun 12 2004 Nice.
It wasn't mentioned in the docs, but I had a slight inkling that it might be the case that one could have InterfaceTemplates using the same syntax as ClassTemplates (ie class ClassName(T) : [superclass [, interfaces] <classbody>). The following example compiled and ran correctly, outputting "1\n4\n" as expected. Perhaps this warrants a mention in the documentation under Templates, alongside "Class Templates"? // begin test.d interface Foo(T) { int aFunction(T anArgument); } class Bar(T) : Foo!(T) { int aFunction(T anArgument) { return anArgument.size; } } int main(char[][] args) { Bar!(ubyte) one = new Bar!(ubyte); Bar!(int) two = new Bar!(int); ubyte oneVar = 16; int twoVar = 400000; printf("%i\n%i\n", one.aFunction(oneVar), two.aFunction(twoVar)); return 0; } // end test.d
Jun 12 2004
Nice. [btw, and please tell me to shove it if this seems rude, but I'm fascinated at the pronunciation of your name. Any chance you could give me a little phonetic pronunciation? :-) (I'm one of the few residents of Australia that goes crazy when the newsreaders mispronounce "foreign" names; the BBC it ain't!!) ] "Sigbjørn Lund Olsen" <sigbjorn lundolsen.net> wrote in message news:caffuc$2vtp$1 digitaldaemon.com...It wasn't mentioned in the docs, but I had a slight inkling that it might be the case that one could have InterfaceTemplates using the same syntax as ClassTemplates (ie class ClassName(T) : [superclass [, interfaces] <classbody>). The following example compiled and ran correctly, outputting "1\n4\n" as expected. Perhaps this warrants a mention in the documentation under Templates, alongside "Class Templates"? // begin test.d interface Foo(T) { int aFunction(T anArgument); } class Bar(T) : Foo!(T) { int aFunction(T anArgument) { return anArgument.size; } } int main(char[][] args) { Bar!(ubyte) one = new Bar!(ubyte); Bar!(int) two = new Bar!(int); ubyte oneVar = 16; int twoVar = 400000; printf("%i\n%i\n", one.aFunction(oneVar), two.aFunction(twoVar)); return 0; } // end test.d
Jun 12 2004