October 16, 2003 implicit conversions | ||||
---|---|---|---|---|
| ||||
This has been touched before, but anyway... Is there a way to get this kind of behavior in D? class Complex { private double re,im; this() { this(r); } this(double r) { this(r,0); } this(double r,double i) { re=r; im=i; } } void main() { Complex x = new Complex(); x=4; //this x=cast(Complex)4; //or maybe even this } I know it can be done explicitly calling the appropiate constructor, but I'd like to also do it like this. ------------------------- Carlos Santander This has been touched before, but anyway... Is there a way to get this kind of behavior in D? class Complex { private double re,im; this() { this(r); } this(double r) { this(r,0); } this(double r,double i) { re=r; im=i; } } void main() { Complex x = new Complex(); x=4; //this x=cast(Complex)4; //or maybe even this } I know it can be done explicitly calling the appropiate constructor, but I'd like to also do it like this. ------------------------- Carlos Santander |
October 27, 2003 Re: implicit conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | "Carlos Santander B." <carlos8294@msn.com> wrote in message news:bmmrol$17vr$1@digitaldaemon.com... > This has been touched before, but anyway... > > Is there a way to get this kind of behavior in D? > > class Complex { > private double re,im; > this() { this(r); } > this(double r) { this(r,0); } > this(double r,double i) { re=r; im=i; } > } > > void main() { > Complex x = new Complex(); > x=4; //this > x=cast(Complex)4; //or maybe even this > } > > I know it can be done explicitly calling the appropiate constructor, but I'd > like to also do it like this. At the moment there isn't a way, but perhaps this should be dealt with. |
Copyright © 1999-2021 by the D Language Foundation