ALERT

[FREE DEMO] Deploy Your Enterprise Cloud in Minutes

Operator Overloading

Definition - What does Operator Overloading mean?

Operator overloading is a technique by which operators used in a programming language are implemented in user-defined types with customized logic that is based on the types of arguments passed.

Operator overloading facilitates the specification of user-defined implementation for operations wherein one or both operands are of user-defined class or structure type. This helps user-defined types to behave much like the fundamental primitive data types. Operator overloading is helpful in cases where the operators used for certain types provide semantics related to the domain context and syntactic support as found in the programming language. It is used for syntactical convenience, readability and maintainability.

Java does not support operator overloading, except for string concatenation for which it overloads the + operator internally.

Techopedia explains Operator Overloading

Operators are referenced using operator notation in expressions and functional notation in declarations. The syntax, precedence and associativity of an operator cannot be changed by using user-defined operator declarations.

For example, operators in C# are categorized based on the type of operation they perform. Some of them are overloaded in user-defined types by defining them in static member functions and using the operator keyword. The parameters of the operator function represent the operands, while the return type of an operator function represents the result of the operation. Overloading is implemented in pairs for operators, such as comparison operators like "==" and "!=". The Equals() method for these operators should be overridden to avoid a compiler warning. Overloading is not to be used for operators such as conditional, logical ( and !!), assignment (+=, -=, etc.), casting and array indexing ([]).

It is highly recommended that operator overloading be implemented such that the results produced are what are intuitively expected out of the default implementation of the operator. Certain mathematical rules such as commutative law, applicable to expressions with two operands, cannot be applicable when used in overloading for types as they are only defined for numerical operands.

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
"Techopedia" on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.