www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Template problem

reply David Medlock <amedlock nospam.org> writes:
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?
Mar 09 2005
parent reply xs0 <xs0 xs0.com> writes:
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
Mar 09 2005
parent reply David Medlock <amedlock nospam.org> writes:
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....
Mar 09 2005
parent xs0 <xs0 xs0.com> writes:
 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
Mar 09 2005