[Issue 3055] New: & operator doesn't get correct func to construct the delegate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 6 19:36:16 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3055

           Summary: & operator doesn't get correct func to construct the
                    delegate
           Product: D
           Version: 2.028
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: davidl at 126.com


import std.stdio;
class t
{
        void func(){writefln("t");}
        void delegate() getdelegate(){return &t.func; } // this doesn't return
the delegate of t.func
}

class v:t
{
        void func(){writefln("v");}
}

class r:v
{
        void func(){writefln("r");}
        void delegate() getdelegate(){return t.getdelegate(); }
}

void main()
{
        r p= new r;
        p.getdelegate()();
}

h3 gave me the solution which can work correctly:
import std.stdio;
class t
{
    void func(){writefln("t");}
    void delegate() getdelegate(){ static void function() getfuncptr() { return
&func; } auto res = &func; res.funcptr = getfuncptr; return res; }
}

class v:t
{
    void func(){writefln("v");}
}

class r:v
{
    void func(){writefln("r");}
    void delegate() getdelegate(){return t.getdelegate(); }
}

void main()
{
    r p= new r;
    p.getdelegate()();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list