Templates with the same name as methods not legal?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Apr 19 05:00:07 PDT 2007


Simen Haugen wrote:
> If I try to call a template when a method with the same name exists I get a 
> compiler error:
> 
> template isInteger(T)
> {
>  static if (is(T == int))
>   const bool isInteger = true;
>  else
>   const bool isInteger = false;
> }
> 
> class Test
> {
>  bool isInteger()
>  {
>   return isInteger!(int); // Yields an compiler error
>  }
> }
> 
> Gives me the error:
> test.d(15): template instance isInteger is not a template declaration, it is 
> a function

Naming the member function "isInteger" hides the "isInteger" name for 
the template while inside the class. The method should "return 
.isInteger!(int);" instead (notice the added '.') to use the global 
isInteger template.


More information about the Digitalmars-d-learn mailing list