May 03, 2016 struct cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
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. |
May 03, 2016 Re: struct cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
Posted in reply to chmike | Oops! Stupid of me. There were three bugs in the code. Correct code is as follow: 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!Data(true, new Data); idx["test2"] = IdxElem!Data(false, new Data); writeln(idx["test2"].data.m); writeln("Hello world!"); } |
Copyright © 1999-2021 by the D Language Foundation