www.digitalmars.com         C & C++   DMDScript  

D - Overloading

reply ben <zander echotech.ca> writes:
Hello Everybody

I have broken my wrist so I will keep this sort.. is there any way overload 
were the return is the unique section.. Just an example:

function long  add(int, int)
function int   add(int, int)

main() {
        long a;
        int b; 
        a = add(1,1) // this would use the first add
        b = add(1,1) // this would use the second add
}

Thanks Ben
Jun 26 2002
parent reply "anderson" <anderson firestar.com.au> writes:
Short answer is NO.

D does not support overloading. You'd have to do something like

long  addl(int, int)
int   addi(int, int)

I've been tring to convice Walter to consider explicit overloading using the
cast idea Pavel came up with.

//For return types
float abs(float n) {} //Default
int cast(int, long) abs(float n) {}
int cast(double) abs(float n) {}

//For parameters
float abs(float n) {} //Default
float abs(float cast(int, long) n) {}
float abs(float cast(double) n) {}


"ben" <zander echotech.ca> wrote in message
news:afcb1q$158i$1 digitaldaemon.com...
 Hello Everybody

 I have broken my wrist so I will keep this sort.. is there any way
overload
 were the return is the unique section.. Just an example:

 function long  add(int, int)
 function int   add(int, int)

 main() {
         long a;
         int b;
         a = add(1,1) // this would use the first add
         b = add(1,1) // this would use the second add
 }

 Thanks Ben
Jun 26 2002
parent reply "anderson" <anderson firestar.com.au> writes:
"anderson" <anderson firestar.com.au> wrote in message
news:afcgkn$1etm$1 digitaldaemon.com...
 Short answer is NO.
D does not support return overloading. You'd have to do something like long addl(int, int) int addi(int, int)
 I've been tring to convice Walter to consider explicit overloading using
the
 cast idea Pavel came up with.

 //For return types
 float abs(float n) {} //Default
 int cast(int, long) abs(float n) {}
 int cast(double) abs(float n) {}

 //For parameters
 float abs(float n) {} //Default
 float abs(float cast(int, long) n) {}
 float abs(float cast(double) n) {}


 "ben" <zander echotech.ca> wrote in message
 news:afcb1q$158i$1 digitaldaemon.com...
 Hello Everybody

 I have broken my wrist so I will keep this sort.. is there any way
overload
 were the return is the unique section.. Just an example:

 function long  add(int, int)
 function int   add(int, int)

 main() {
         long a;
         int b;
         a = add(1,1) // this would use the first add
         b = add(1,1) // this would use the second add
 }

 Thanks Ben
Jun 26 2002
parent ben <zander echotech.ca> writes:
Ok thanks. I guess that would lead to alot of problem code, but it could be 
usefull for math programming, I wish I had an example off hand but I don't, 
as i have been working on a few porjects i have noticed that I could not do 
that with c++ and it would have helped me in a few occations.

Thanks Ben

anderson wrote:

 
 "anderson" <anderson firestar.com.au> wrote in message
 news:afcgkn$1etm$1 digitaldaemon.com...
 Short answer is NO.
D does not support return overloading. You'd have to do something like long addl(int, int) int addi(int, int)
 I've been tring to convice Walter to consider explicit overloading using
the
 cast idea Pavel came up with.

 //For return types
 float abs(float n) {} //Default
 int cast(int, long) abs(float n) {}
 int cast(double) abs(float n) {}

 //For parameters
 float abs(float n) {} //Default
 float abs(float cast(int, long) n) {}
 float abs(float cast(double) n) {}


 "ben" <zander echotech.ca> wrote in message
 news:afcb1q$158i$1 digitaldaemon.com...
 Hello Everybody

 I have broken my wrist so I will keep this sort.. is there any way
overload
 were the return is the unique section.. Just an example:

 function long  add(int, int)
 function int   add(int, int)

 main() {
         long a;
         int b;
         a = add(1,1) // this would use the first add
         b = add(1,1) // this would use the second add
 }

 Thanks Ben
Jun 27 2002