Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Operator Overloading

< >
Example from 1 languages: Python
# Python Program illustrate how # to overload an binary + operator class A: def __init__(self, a): self.a = a # adding two objects def __add__(self, o): return self.a + o.a ob1 = A(1) ob2 = A(2) ob3 = A("Geeks") ob4 = A("For") print(ob1 + ob2) print(ob3 + ob4)
Example from 1 languages: C3
fn int IntList.get(IntList* this, int idx) @operator([]) { return this.vals[idx]; } ... IntList x = ... foo(x[1]);
Example from 1 languages: Wa-lang
#wa:operator + MyInt_add type MyInt :struct { V: int } func MyInt_add(x, y: MyInt) => int { return x.V + y.V } func main { x1 := MyInt{V: 100} x2 := MyInt{V: 42} println(x1 + x2) }
Example from 1 languages: MoonBit
struct T { x:Int } derive(Show) fn op_add(self: T, other: T) -> T { { x: self.x + other.x } } fn main { let a = { x:0, } let b = { x:2, } println(a + b) }
Example from 1 languages: Wolfram Language
f[x_Integer] := x^2; f[x_String] := "not a number"; f[x_Symbol] := x^2;
Example from 1 languages: Speedie
str = "a" + "b" array <~ str
*

Languages with Operator Overloading include Python, C++, Perl, Ruby, PHP, C#, R, Rust, Swift, Scala, MATLAB, Lua, Kotlin, Haskell, Clojure, Dart, Ada, D, Chapel, Groovy, F#, Smalltalk, Visual Basic .NET, C3, Eiffel, Wa-lang, MoonBit, Wolfram Language, Ceylon, Raku, Io, Object Pascal, Seed7, FreeBASIC, Speedie, Free Pascal

*

Languages without Operator Overloading include JavaScript, C, Java, Go, TypeScript, Objective-C, Visual Basic, Pascal, BASIC, Lil, Modula-2, progsbase, Veryl, Jule

*

View all concepts with or missing a hasOperatorOverloading measurement

*

Read more about Operator Overloading on the web: 1. 2.

- Build the next great programming language · Add · Issues · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements