www.digitalmars.com         C & C++   DMDScript  
Archives

D Programming
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger
D.gnu
D

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics


digitalmars.D.bugs - [Issue 3055] New: & operator doesn't get correct func to construct the delegate

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 digitalmars.com
        ReportedBy: davidl 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: -------
Jun 06 2009