digitalmars.D - Will alias this work for classes too?
- Janice Caron (13/13) Sep 12 2007 Will alias this work for classes too?
- davidl (5/18) Sep 12 2007 Ah, I haven't noticed such brilliant!
- Jascha Wetzel (3/20) Sep 13 2007 that would be a different syntax for regular MI and is therefore
- Janice Caron (7/9) Sep 13 2007 "alias this" is already slated in in the Walter Andrei document.
- Jascha Wetzel (6/17) Sep 13 2007 that depends on what you want to do on name collisions. structs don't
- Sean Kelly (8/18) Sep 13 2007 If I had to guess, I'd say "alias this" will basically perform a mix-in
- Jascha Wetzel (25/37) Sep 13 2007 mixin merely copies declarations at compile-time. "alias b this" in the
Will alias this work for classes too? An in, class A { int a; } class B { int b; } class C { int c; } class X : A { B b; C c; alias b this; alias c this; } Fake multiple inheritance!
Sep 12 2007
Ah, I haven't noticed such brilliant! 在 Thu, 13 Sep 2007 06:08:48 +0800,Janice Caron <caron800 googlemail.com> 写道:Will alias this work for classes too? An in, class A { int a; } class B { int b; } class C { int c; } class X : A { B b; C c; alias b this; alias c this; } Fake multiple inheritance!-- 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
Sep 12 2007
Janice Caron wrote:Will alias this work for classes too? An in, class A { int a; } class B { int b; } class C { int c; } class X : A { B b; C c; alias b this; alias c this; } Fake multiple inheritance!that would be a different syntax for regular MI and is therefore probably not going to happen.
Sep 13 2007
On 9/13/07, Jascha Wetzel <"[firstname]" mainia.de> wrote:that would be a different syntax for regular MI and is therefore probably not going to happen."alias this" is already slated in in the Walter Andrei document. Walter apparently /wants/ "alias this", and it looks like it will work as I outlined - at least for structs. Classes? I don't know. That's why I asked. It's not real multiple inheritance. Nobody should pretend it is. But it does "fake it" to a certain extent..
Sep 13 2007
Janice Caron wrote:On 9/13/07, Jascha Wetzel <"[firstname]" mainia.de> wrote:that depends on what you want to do on name collisions. structs don't have inheritance or virtual functions, which greatly simplifies the problem. once you deal with inheritance and virtual functions as intuitively expected (at least as I intuitively expected), it'll be like real MI.that would be a different syntax for regular MI and is therefore probably not going to happen."alias this" is already slated in in the Walter Andrei document. Walter apparently /wants/ "alias this", and it looks like it will work as I outlined - at least for structs. Classes? I don't know. That's why I asked. It's not real multiple inheritance. Nobody should pretend it is. But it does "fake it" to a certain extent..
Sep 13 2007
Janice Caron wrote:On 9/13/07, Jascha Wetzel <"[firstname]" mainia.de> wrote:If I had to guess, I'd say "alias this" will basically perform a mix-in of the data. So I don't see any reason why it couldn't work for classes.that would be a different syntax for regular MI and is therefore probably not going to happen."alias this" is already slated in in the Walter Andrei document. Walter apparently /wants/ "alias this", and it looks like it will work as I outlined - at least for structs. Classes? I don't know. That's why I asked.It's not real multiple inheritance. Nobody should pretend it is. But it does "fake it" to a certain extent..See this link for an example of mixin multiple inheritance: http://www.invisibleduck.org/~sean/code/io/stream.d It's not an approach I'd want to use regularly, but it can come in handy for eliminating code duplication in some instances. Sean
Sep 13 2007
Sean Kelly wrote:Janice Caron wrote:mixin merely copies declarations at compile-time. "alias b this" in the sense of the version from Walter's and Andrei's slides, would have to use the reference to the aggregated object to access it's members. a couple of issues come to mind: - while a method that has been mixed in can be overridden in a subclass, a method that has been imported via alias-this can't (unless alias-this would change the vtable of the importing class, which would lead to real MI). - consider this: class A { void foo(int); } class B { void foo(int); } class C : A { override void foo(int); } class D : B { C c; alias C this; } what is D.foo? - the diamond problem of MI also arises - accessing a member (even if it's of primitive type) can result in an access violation although the reference used by the caller is non-null - the aggregated object might be null. sure, these issues can be overcome, but it appears similarly complex as real MI to me.On 9/13/07, Jascha Wetzel <"[firstname]" mainia.de> wrote:If I had to guess, I'd say "alias this" will basically perform a mix-in of the data. So I don't see any reason why it couldn't work for classes.that would be a different syntax for regular MI and is therefore probably not going to happen."alias this" is already slated in in the Walter Andrei document. Walter apparently /wants/ "alias this", and it looks like it will work as I outlined - at least for structs. Classes? I don't know. That's why I asked.
Sep 13 2007