constructor instead of opCall for an instance of a template alias
comco
void.unsigned at gmail.com
Sat Nov 24 12:34:38 PST 2012
I have the following snippet:
struct A(alias Method)
{
string s;
this(Method method) {
method(s); // 5
}
}
struct B
{
this(int i) { }
void opCall(string s) { }
}
void main() {
A!B(B(0));
}
This code fails to compile with the following errors:
test.d(5): Error: constructor test.B.this (int i) is not callable
using argument types (string)
test.d(5): Error: cannot implicitly convert expression (this.s)
of type string to int
test.d(17): Error: template instance test.A!(B) error
instantiating
shell returned 1
It looks like the compiler is confusing the `method` instance
parameter with the `Method` class.
If I replace line 5 with `method.opCall(s);` it compiles.
Can you explain this behaviour please?
More information about the Digitalmars-d-learn
mailing list