https://issues.dlang.org/show_bug.cgi?id=12773

nick <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]
                   |                            |m

--- Comment #2 from nick <[email protected]> ---
I believe this behaviour is by design. There is no implicit conversion, because
&C.bar is not a delegate, it is a function pointer. The following code works as
expected:


alias Func = void function();
alias Del = void delegate();

class C
{
    string str = "bar";
    static void foo() { }
    void bar() { writeln(str); }
}

void main()
{
    {
        // Func func = C.foo;  // disallowed, since this is a function call
    }

    {
        Func func = &C.foo;  // ok, the proper syntax usage.
        func();  // ok
    }

    {
        Func func = &C.bar;  // correct

        C c = new C;
        Del del = &c.bar;    // correct

        Del del2;
        del2.funcptr = func;
        del2.ptr = cast(void*)c;
        del2();               // works, output is "bar"
    }
}

--

Reply via email to