Help with template problem

Janice Caron caron800 at googlemail.com
Tue Nov 6 23:50:15 PST 2007


> -auto a = new A!(N)();
> +auto a = new A!(123)();
>
> Try that. :)

If you mean the one inside main(), you're right in that that shouldn't
be there. That was a copy/paste error. But I don't need to rewrite the
line, I can just delete it! The compile errors are still there. (I
also took out the comments). So here's the newest version:

/////////////////////////////////////////////////
module main;

class A(uint N)
{
   uint n = 0;

   this()
   {
       uint m = n;
   }
}

void doTest(uint N)()
{
   auto a = new A!(N)();
}

int main()
{
   doTest!(1)();
   doTest!(2)();

   return 0;
}

/////////////////////////////////////////////////


The compile errors are:
test.d(7): Error: this for n needs to be type A not type test.A!(N).A
test.d(7): class test.A!(N).A member n is not accessible
test.d(13): template instance test.A!(N) error instantiating
test.d(19): template instance test.doTest!(2) error instantiating

Replacing the N with 123 inside doTest() makes all the compilation
errors go away, and it now compiles. But of course, now it doesn't do
what it needs to do. At that point in the code, N is a compile time
constant (being the tempate parameter), and so - unless I've
misunderstood something - should be every bit as compilable as 123.



More information about the Digitalmars-d mailing list