www.digitalmars.com         C & C++   DMDScript  

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

reply d-bugmail puremagic.com writes:
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
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3055


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim maxim-fomin.ru
         Resolution|                            |INVALID



---
Taking address of member function in the form of &A.foo yields as expected a
function pointer, not delegate. To get delegate one need to omit class name.

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