www.digitalmars.com         C & C++   DMDScript  

D - implicit casting of class variable to char[]

reply Yan <Yan_member pathlink.com> writes:
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");
Feb 16 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
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");

Feb 18 2004