Thread overview | |||||
---|---|---|---|---|---|
|
January 25, 2004 operator overloading | ||||
---|---|---|---|---|
| ||||
1. i like D very much1 2. I only recently got some time to start exploring it and i have a question: i have this code: class Cout { Cout opShl(char[] x) { printf("%.*s",x); return this; } Cout opShl(int x) { printf("%d",x); return this; } ... } The idea is to make a class cout that would act like c++ cout. Is there any way to write something like: Cout opShl(Cout c,A f) { //printf that prints object f of type A return c; } it doesn't work the way i would like it, i have to explicitly call the function ti print type A! |
January 25, 2004 Re: operator overloading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | opShl_r will make you happy! "Ivan Senji" <ivan.senji@public.srce.hr> wrote in message news:bv163k$ckg$1@digitaldaemon.com... > 1. i like D very much1 > 2. I only recently got some time to start exploring it and i have a > question: > i have this code: > > class Cout > { > Cout opShl(char[] x) > { > printf("%.*s",x); > return this; > } > Cout opShl(int x) > { > printf("%d",x); > return this; > } > ... > } > > The idea is to make a class cout that would act like c++ cout. > Is there any way to write something like: > Cout opShl(Cout c,A f) > { > //printf that prints object f of type A > return c; > } > > it doesn't work the way i would like it, i have to explicitly call the function ti print type A! > > > > |
January 26, 2004 Re: operator overloading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | what if you have a toString() function in A and then call printf( f.toString()); Phill. "Ivan Senji" <ivan.senji@public.srce.hr> wrote in message news:bv163k$ckg$1@digitaldaemon.com... > 1. i like D very much1 > 2. I only recently got some time to start exploring it and i have a > question: > i have this code: > > class Cout > { > Cout opShl(char[] x) > { > printf("%.*s",x); > return this; > } > Cout opShl(int x) > { > printf("%d",x); > return this; > } > ... > } > > The idea is to make a class cout that would act like c++ cout. > Is there any way to write something like: > Cout opShl(Cout c,A f) > { > //printf that prints object f of type A > return c; > } > > it doesn't work the way i would like it, i have to explicitly call the function ti print type A! > > > > |
Copyright © 1999-2021 by the D Language Foundation