On Wednesday, 4 September 2013 at 19:36:08 UTC, ilya-stromberg
wrote:
I have some code like this:
struct Foo
{
this(int i)
{
//do something useful
}
}
void bar(Foo f)
{
//do something else
}
void main()
{
Foo f = 5;//works
bar(f);//works
bar(Foo(5));//works
bar(5);//Error: function app.bar (Foo f) is not callable using
argument types (int)
}
D can't implicitly convert type "int" to type "Foo", but
constructor "Foo(int)" exists. Explicit conversion works fine.
What should I do to support this convertion implicitly?
What's about:
void bar(int i) {
bar(Foo(i));
}
?