February 16, 2004 implicit casting of class variable to char[] | ||||
---|---|---|---|---|
| ||||
hi, why not to cast class variable to char[] automatically? NewClass { NewClass opAdd() {...} NewClass opDiv() {...} char[] toString() {...} } NewClass v1 = new NewClass(); NewClass v2 = new NewClass(); // This is more readable (java way): printf("v1+v2="~(v1+v2)~" v1/v2="~(v1/v2)~" \n"); // Then D way: printf("v1+v2="~(v1+v2).toString()~" v1/v2="~(v1/v2).toString()~" \n"); |
February 19, 2004 Re: implicit casting of class variable to char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Yan | Because implicit conversions are generally, though by no means exclusively, a bad thing. "Yan" <Yan_member@pathlink.com> wrote in message news:c0qcqm$20k1$1@digitaldaemon.com... > hi, > why not to cast class variable to char[] automatically? > > NewClass { > NewClass opAdd() {...} > NewClass opDiv() {...} > char[] toString() {...} > } > > NewClass v1 = new NewClass(); > NewClass v2 = new NewClass(); > > // This is more readable (java way): > printf("v1+v2="~(v1+v2)~" v1/v2="~(v1/v2)~" \n"); > > // Then D way: > printf("v1+v2="~(v1+v2).toString()~" v1/v2="~(v1/v2).toString()~" \n"); > > > > |
Copyright © 1999-2021 by the D Language Foundation