digitalmars.D.learn - Multiple subtyping
- Joel Christensen (39/39) Aug 25 2011 Hi,
- Timon Gehr (5/41) Aug 25 2011 That is a compiler bug. Alias this does not work properly yet. (at the
- Andrej Mitrovic (2/2) Aug 26 2011 with doesn't work properly with alias this, I've already filed this in
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
Aug 25 2011
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 } } - JoelThat 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.
Aug 25 2011
with doesn't work properly with alias this, I've already filed this in bugzilla though.
Aug 26 2011