Thread overview
operator overloading
Jan 25, 2004
Ivan Senji
Jan 25, 2004
Robert
Jan 26, 2004
Phill
January 25, 2004
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
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
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!
>
>
>
>