# 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)
fn int IntList.get(IntList* this, int idx) @operator([])
{
return this.vals[idx];
}
...
IntList x = ...
foo(x[1]);
f[x_Integer] := x^2;
f[x_String] := "not a number";
f[x_Symbol] := x^2;
str = "a" + "b"
array <~ str
Languages with Operator Overloading include Python, C++, PHP, Perl, Ruby, MATLAB, C#, R, Swift, Scala, Ada, Rust, Kotlin, Haskell, Lua, Clojure, Dart, F#, Eiffel, Smalltalk, D, Groovy, Visual Basic .NET, Io, Ceylon, Object Pascal, Cython, C3, Perl 6, Wolfram Language, Speedie, Seed7, FreeBASIC, Free Pascal, Real-Time Concurrent C
Languages without Operator Overloading include Java, JavaScript, C, Go, Pascal, TypeScript, Objective-C, Visual Basic, Modula-2, BASIC, progsbase, Jule, Pizza, Oracle Java, Deesel, Tick C, cooC, ADLIB, Static Typescript, Extended Pascal, Modula-2+
This question asks: Does the language allow operator overloading?
Read more about Operator Overloading on the web: 1. 2.
HTML of this page generated by Features.ts