struct  cannot deduce function from argument types
    chmike via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Tue May  3 07:31:48 PDT 2016
    
    
  
The following code does not compile and I don't understand why.
import std.stdio;
class Data
{
     string m = "Hello world !";
}
struct IdxElem(D)
{
     bool inUse;
     D data;
}
IdxElem!Data[string] idx;
void main()
{
     idx["test1"] = IdxElem(true, new Data);
     idx["test2"] = IdxElem(false, new Data);
     writeln(idx["test2"].data);
     writeln("Hello world!");
}
This is the error message I get with DMD64 D Compiler v2.068.2
source/app.d(20,27): Error: struct app.IdxElem cannot deduce 
function from argument types !()(bool, Data), candidates are:
source/app.d(9,1):        app.IdxElem(D)
source/app.d(21,27): Error: struct app.IdxElem cannot deduce 
function from argument types !()(bool, Data), candidates are:
source/app.d(9,1):        app.IdxElem(D)
dmd failed with exit code 1.
I get the same error even if I add a constructor to IdxElem that 
sets the member variables with its two arguments.
    
    
More information about the Digitalmars-d-learn
mailing list