Struct template cannot deduce function from argument types
Luka Aleksic
x at y.z
Wed Jun 27 16:19:56 UTC 2018
Hello,
In the following code:
struct pair(T, U) {
T first;
U second;
this(T arg_first, U arg_second) {
first = arg_first;
second = arg_second;
}
};
void main() {
pair!(char, uint) p1 = pair('a', 1);
}
I am getting the following error:
scratch.d(14): Error: struct scratch.pair cannot deduce function
from argument types !()(char, int), candidates are:
scratch.d(2): scratch.pair(T, U)
Failed: ["/usr/bin/dmd", "-v", "-o-", "scratch.d", "-I."]
Changing the offending line to:
pair!(char, uint) p1 = pair!(char, uint)('a', 1);
fixes the issue.
However I am interested to know why the first code couldn't
deduce the types-- and why does it even have to try to deduce
them, when I explicitly stated that p1 was of the type "pair of
char and uint"?
Thanks,
L. Aleksic
More information about the Digitalmars-d-learn
mailing list