Thread overview | |||||
---|---|---|---|---|---|
|
August 26, 2011 Multiple subtyping | ||||
---|---|---|---|---|
| ||||
Hi, Has anyone had much experience with multiple subtyping. //Org: based on page 232 (6.13.1) in The D Programming Language book //#save(); without storeShape does not work import std.stdio; class Shape { void shape() { writeln( "Shape" ); } } class DataBase { void save() { writeln( "I'm the top - save" ); } } class StoreShape : Shape { private class MyDataBase : DataBase { override void save() { super.save(); writeln( "Data base: save" ); } } private MyDataBase _store; alias _store this; this() { _store = this.new MyDataBase; } } void main() { auto storeShape = new StoreShape; with( storeShape ) { shape(); storeShape.save(); //#save(); without storeShape. does not work } } - Joel |
August 26, 2011 Re: Multiple subtyping | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel Christensen | On 08/26/2011 05:45 AM, Joel Christensen wrote:
> Hi,
>
> Has anyone had much experience with multiple subtyping.
>
> //Org: based on page 232 (6.13.1) in The D Programming Language book
> //#save(); without storeShape does not work
> import std.stdio;
>
> class Shape {
> void shape() {
> writeln( "Shape" );
> }
> }
>
> class DataBase {
> void save() {
> writeln( "I'm the top - save" );
> }
> }
>
> class StoreShape : Shape {
> private class MyDataBase : DataBase {
> override void save() {
> super.save();
> writeln( "Data base: save" );
> }
> }
>
> private MyDataBase _store;
> alias _store this;
>
> this() {
> _store = this.new MyDataBase;
> }
> }
>
> void main() {
> auto storeShape = new StoreShape;
>
> with( storeShape ) {
> shape();
> storeShape.save(); //#save(); without storeShape. does not work
> }
> }
>
> - Joel
>
That is a compiler bug. Alias this does not work properly yet. (at the moment, there can also be only one alias this.)
The reason why it does not work is that the compiler rewrites the with ( ) { } in funny ways.
|
August 26, 2011 Re: Multiple subtyping | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | with doesn't work properly with alias this, I've already filed this in bugzilla though. |
Copyright © 1999-2021 by the D Language Foundation