www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a bug ?

reply Chang Long <changlon gmail.com> writes:
test.d
=========
template newType(size_t N){
         class NewType
         {
                 enum Type       = N ;
         }
}

class A{}

alias Type      = newType!1 ;

N New(N)(){
         return new N();
}

void main(){
         auto a = New!A;
         auto n = New!Type;
}
============


test.d(19): Error: template instance New!(__T7newTypeVmi1Z) does 
not match template declaration New(N)()
Jul 11 2016
parent reply Chang Long <changlon gmail.com> writes:
On Tuesday, 12 July 2016 at 04:38:42 UTC, Chang Long wrote:
 test.d
 =========
 template newType(size_t N){
         class NewType
         {
                 enum Type       = N ;
         }
 }
just find it should be this: template newType(size_t N){ class NewType { enum Type = N ; } alias newType = NewType; }
Jul 11 2016
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/12/16 1:31 AM, Chang Long wrote:
 On Tuesday, 12 July 2016 at 04:38:42 UTC, Chang Long wrote:
 test.d
 =========
 template newType(size_t N){
         class NewType
         {
                 enum Type       = N ;
         }
 }
just find it should be this: template newType(size_t N){ class NewType { enum Type = N ; } alias newType = NewType; }
Just some advice: Name your template NewType, or the class newType, and then it will work. -Steve
Jul 12 2016