On Thu Apr 12 10:08:21 2012, Alexander Stavonin wrote:
> What's about function overloading? Something like this:
>
> fn foo(val: int) {
>     io::println("int");
> }
>
> fn foo(val: str) {
>     io::println("str");
> }
>
> fn main() {
>     foo(1);
>     foo("test");
> }
>
> But :(
>
> main.rs:3:0: 5:1 error: duplicate definition of foo
> main.rs:3 fn foo(val: int) {
> main.rs:4     io::println("int");
> main.rs:5 }
>
> As I understood, similar code can be implemented by using ifase and impl, but 
> it's very cumbersome way.
My personal experience is that you want function overloading to be very 
explicit. Having too much overloading makes it much easier to misread 
code.

So, I personally would not advocate C++-style function overloading.

--
David Rajchenbach-Teller, PhD
 Performance Team, Mozilla

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to