Anyone know what's going on here? (variable with an instantiated template as a type shows up as void when instantiating another template)

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Fri Apr 23 06:38:32 PDT 2010


Gareth Charnock wrote:
> Is this a bug, or am I being dense? I've tried it this on 2.036,2.042 
> and 2.043 and on each the compiler produces errors. Searched bugzilla 
> for "template and instantiated" and "template and instantiate"
> 
> struct A(uint N)  {
> }
> void unary_op(uint N)(A!(N)) {
> }
> void main() {
>     A!(3) a3;
> 
>     pragma(msg,typeof(a3)); //prints A!(3), so a3 is not void, dammit
> 
>     unary_op!3(A);// Error: cannot implicitly convert expression
>                   // (A(uint N)) of type void to A!(N)
>     unary_op(A);  // Error: template template.unary_op(uint N) does not
>                   // match any function template declaration
>                   // Error: template template.unary_op(uint N) cannot
>                   // deduce template function from argument types
>                   // !()(void)   <== what?
> }


You are trying to call unary_op on the template A. Try this instead:

   unary_op!3(a3);
   unary_op(a3);

-Lars



More information about the Digitalmars-d mailing list