[Issue 11456] New: works with -allinst but not without
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 6 14:03:55 PST 2013
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 at puremagic.com
ReportedBy: bugzilla at digitalmars.com
--- Comment #0 from Walter Bright <bugzilla at digitalmars.com> 2013-11-06 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: -------
More information about the Digitalmars-d-bugs
mailing list