Lably
Skip to content

Operator overloading

Feature of some programming languages

  • 18 min read
  • 5 chapters

Related on Lably

Through Computer programming, Polymorphism (computer science) and Operator (computer programming)

Rationale

Operator overloading is syntactic sugar, and is used because it allows programming using notation nearer to the target domain and allows user-defined types a similar level of syntactic support as types built into a language. It is common, for example, in scientific computing, where it allows computing representations of mathematical objects to be manipulated with the same syntax as on paper.

Operator overloading does not change the expressive power of a language (with functions), as it can be emulated using function calls. For example, consider variables a, b and c of some user-defined type, such as matrices:

a + b * c

In a language that supports operator overloading, and with the usual assumption that the * operator has higher precedence than the + operator, this is a concise way of writing:

Add(a, Multiply(b, c))

However, the former syntax reflects common mathematical usage.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication