What is the overload of the operator?

Operator overload is a computer programming language function that allows the programmer to rewrite the default operator. When the operator's function is overloaded, it can be declared using its own arguments that are different types of data than what the operator was able to process by default. New parameters can be primitive or user -defined types. In the body, the prevailing functioner can manipulate the parameter values ​​as needed. Using overload the operator, the programmer can create intuitive shortcuts to handle data types defined by the user or adjust how the default data types are handled. Operators, including the adding symbol, can be rewritten so that if they are used as binary operators between two own data types, they return the depokuta users. Likewise, the UNARY operator could be rewritten, as well as the increment operator to increase the internal value within the user -defined user.

As soon as the operator is overloaded, the compiler must decide what to do when he encounters an overloaded operator. The compiler decides on the right measure to be taken on the basis of what types of data are used as operands or in conjunction with the operator. If operands that are the values ​​of parameters for the operator's function, user -defined data types, the compiler chooses an overloaded function that has parameters that correspond to the operands used.

Computer languages ​​differ in how this type of ad-hoc polymorphism enable. Different languages ​​can allow the creation of new operators, overloading all or some of its operators, or may not allow the operator overload at all. C ++, C#, PHP and perlvs all allow you to overload some of their operators. Overloading the operator is not allowed in C, Java and JavaScript.

Overload of operators and overloading functions in general were the subject of some debate. Some saythat giving the programmer freedom of change the way the operator behaves can present the potential for creating unintentional errors of other programmers who use the adapted code. The recurring view suggests that the operator's congestion overload gives programmers the ability to create an intuitive and concise code that will be easier to understand, make less and reduce errors.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?