Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 09, 2005 Template problem | ||||
---|---|---|---|---|
| ||||
import std.stdio; template Test( C : char ) { void print() { writefln( C ); } } void main( char[][] arg ) { Test!('a').print(); } ---------- Capture Output ---------- > "C:\dmd\bin\dmd.exe" -debug -c C:\proj\temp\test.d C:\proj\temp\test.d(16): template instance Test!(97) does not match any template declaration C:\proj\temp\test.d(16): undefined identifier template instance Test!(97).print C:\proj\temp\test.d(16): function expected before (), not 'void' Anyone see what is wrong here? |
March 09, 2005 Re: Template problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Medlock | David Medlock wrote:
>
> import std.stdio;
> template Test( C : char )
> {
> void print()
> {
> writefln( C );
> }
> }
>
> void main( char[][] arg )
> {
> Test!('a').print();
> }
>
> ---------- Capture Output ----------
> > "C:\dmd\bin\dmd.exe" -debug -c C:\proj\temp\test.d
> C:\proj\temp\test.d(16): template instance Test!(97) does not match any template declaration
> C:\proj\temp\test.d(16): undefined identifier template instance Test!(97).print
> C:\proj\temp\test.d(16): function expected before (), not 'void'
>
>
> Anyone see what is wrong here?
It should be "char C" instead of "C : char"...
xs0
|
March 09, 2005 Re: Template problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to xs0 | xs0 wrote: > David Medlock wrote: >> Anyone see what is wrong here? > > > It should be "char C" instead of "C : char"... > > > xs0 Thanks. Don't know why I thought the : syntax was specialization.... What really threw me off is if you make it template Test( C ) it still fails, which is kind of weird, as there is no other Test template.... |
March 09, 2005 Re: Template problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Medlock | > Don't know why I thought the : syntax was specialization....
>
> What really threw me off is if you make it
>
> template Test( C )
>
> it still fails, which is kind of weird, as there is no other Test template....
C matches types
char C matches actual chars (values)
C : Type matches Type or its derivative (or maybe just Type, not sure)
C : char matches just type char (not a char value or even char typedef)
char C : 'a' matches the character 'a'
xs0
|
Copyright © 1999-2021 by the D Language Foundation