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?

Reply via email to