Languages Features Calendar About Lists Add Language
GitHub icon

Operator Overloading

Operator Overloading

Operator Overloading is a language feature.

Where different operators have different implementations depending on their arguments.

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

Languages with Operator Overloading include Python, C++, PHP, Ruby, R, Perl, C#, Scala, MATLAB, Swift, Rust, Haskell, Lua, Clojure, Kotlin, Ada, Dart, Groovy, F#, D, Smalltalk, Eiffel, Io, Visual Basic .NET, Perl 6, Seed7, Ceylon, Object Pascal, Free Pascal, FreeBASIC

Example from 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)

Article source

PLDB - Build the next great programming language. v5.0.0 - Acknowledgements · Email · GitHub