Operator Overloading is an actively used design pattern. Where different operators have different implementations depending on their arguments.
- the Operator Overloading wikipedia page
- Have a question about Operator Overloading not answered here? Email me and let me know how I can help.
- Read more about Operator Overloading
Languages with Operator Overloading include ada, ceylon, clojure, cpp, csharp, d, dart, eiffel, f-sharp, free-pascal, freebasic, groovy, haskell, io, kotlin, lua, matlab, object-pascal, perl-6, perl, php, python, r, ruby, rust, scala, seed7, smalltalk, swift, visual-basic-dot-net
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)
Last updated June 22nd, 2020