September 07, 2004 a couple of questions.. (mixins and inout) | ||||
---|---|---|---|---|
| ||||
class A { void func(){} template funcdecl(Type) { void func(Type t){writefln(t);} } mixin funcdecl!(int) ; mixin funcdecl!(float) ; } We all know this doesn't work but it can be fixed by adding aliases: mixin funcdecl!(int) a1; mixin funcdecl!(float) a2; alias a1.func func; alias a2.func func; And now the name overloading works, but: what if i want to mixin constructors, how can i do that? template funcdecl(Type) { this(Type t){} } mixin funcdecl!(int) a1; mixin funcdecl!(float) a2; alias a1.this this; alias a2.this this; This doesn't work! And another question: class A{} void func(inout A a){} func(new A); --> this doesn't work why? (new A is not an lvalue) If C++ can do it why not D? It is a lot more complicated to assign temporary objects to variables and then pass it as an inout param then to pass it directly. |
September 07, 2004 Re: a couple of questions.. (mixins and inout) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | Sorry! Wrong NG :) "Ivan Senji" <ivan.senji@public.srce.hr> wrote in message news:chjmjn$268h$1@digitaldaemon.com... > class A > { > void func(){} > template funcdecl(Type) > { > void func(Type t){writefln(t);} > } > mixin funcdecl!(int) ; > mixin funcdecl!(float) ; > } > > We all know this doesn't work but it can be fixed by adding aliases: > mixin funcdecl!(int) a1; > mixin funcdecl!(float) a2; > alias a1.func func; > alias a2.func func; > > And now the name overloading works, but: > what if i want to mixin constructors, how can i do that? > > template funcdecl(Type) > { > this(Type t){} > } > mixin funcdecl!(int) a1; > mixin funcdecl!(float) a2; > alias a1.this this; > alias a2.this this; > > This doesn't work! > > And another question: > > class A{} > void func(inout A a){} > func(new A); > --> this doesn't work why? (new A is not an lvalue) > If C++ can do it why not D? > > It is a lot more complicated to assign temporary objects > to variables and then pass it as an inout param then to pass > it directly. > > > > > > > |
Copyright © 1999-2021 by the D Language Foundation