Re: [Vala] Operator overloading



Java does not support operator overloading.
Python does:

class Complex:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __add__(self, other):
        return Complex(self.x + other.x, self.y + other.y)

Even though Python already has complex numbers build into the
language, this is used for types in the standard library such as
decimal, which stores numbers as base-10 to avoid errors that come
with converting base-10 to floating point. As you can imagine, this is
extremely useful for accounting applications.

Laszlo

On Sun, Mar 22, 2009 at 6:46 PM, pancake <pancake youterm com> wrote:
Yu Feng wrote:
Does java support operator overriding? Python? C#?


c# does. Here's a sample syntax:

public static Complex operator +(Complex c1,Complex c2)
{
 Complex temp = new Complex();
 temp.x = c1.x+c2.x;
 temp.y = c1.y+c2.y;
 return temp;
}



--pancake
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]