Error: this for <method name> needs to be type S not type	MapResult!...
    Peter Neubauer 
    peterneubauer2 at gmail.com
       
    Sat Jun 29 12:43:59 PDT 2013
    
    
  
Please explain why this error happens in the following code:
import std.algorithm;
struct S
{
   void foo ()
   {
     int f1 (int a) { return conv(a); }
     int delegate (int) f2 = &conv;
     int[] x = [1, 2, 3];
     x.map!conv;    // ERROR
     x.map!f1;      // fine
     x.map!f2;      // also fine
   }
   int conv (int a)
   {
     return a+1;
   }
}
--- compile output:
/usr/include/d/std/algorithm.d(404): Error: this for conv needs to be 
type S not type MapResult!(conv, int[])
/usr/include/d/std/algorithm.d(438): Error: this for conv needs to be 
type S not type MapResult!(conv, int[])
/usr/include/d/std/algorithm.d(450): Error: this for conv needs to be 
type S not type MapResult!(conv, int[])
/usr/include/d/std/algorithm.d(390): Error: template instance 
std.algorithm.MapResult!(conv, int[]) error instantiating
/home/peter/proggen/goliza.reduced/gtp.d(12):        instantiated from 
here: map!(int[])
/home/peter/proggen/goliza.reduced/gtp.d(12): Error: template instance 
std.algorithm.map!(conv).map!(int[]) error instantiating
---
Thanks,
-Peter
    
    
More information about the Digitalmars-d-learn
mailing list