www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11456] New: works with -allinst but not without

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11456

           Summary: works with -allinst but not without
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bugzilla digitalmars.com



14:03:53 PST ---
Andrei reports:

This works with -allinst but not without:

import std.typecons;

interface IDrawable
{
    void drawLine(int x1, int y1, int x2, int y2);
}

class ImageDraw  // note: it does not inherit IDrawable.
{
    void drawLine(int x1, int y1, int x2, int y2) { }
}

/** Draw a rectangle outline. */
void drawRect(IDrawable draw)
{
    draw.drawLine(  0,   0, 100,   0);
    draw.drawLine(100,   0, 100, 100);
    draw.drawLine(  0, 100, 100, 100);
    draw.drawLine(  0,   0,   0, 100);
}

void main()
{
    auto imageDraw = new ImageDraw();
    //drawRect(imageDraw);  // error: can't call this, ImageDraw is not an
IDrawable.

    // perform a structural cast.
    IDrawable i = wrap!IDrawable(imageDraw);
    drawRect(i);  // and now imageDraw can act as an IDrawable.
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 06 2013
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11456


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



14:09:49 PST ---
Is this OSX-only?

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