The document discusses operator overloading in C++. It defines operator overloading as allowing operators to perform special operations on user-defined types. As an example, the + operator can be overloaded to perform string concatenation in addition to numeric addition. It categorizes operators as unary, which operate on a single operand, and binary, which operate on two operands. The document provides an example of overloading the * operator to multiply the data members of a class. When called on two class objects, it returns a new object with the multiplied data members.
Introduces G.Balaji, Assistant Professor in Computer Science at Vivekananda College.
Defines operators, specifically focusing on the '+' symbol. Explains operator overloading in C++, highlighting its extensibility and providing an example of string concatenation.
Differentiates between unary and binary operators in C++. Discusses the structure of overloading operators with return types and function names.
Explains binary operator overloading with an example class 'multiply'. Shows how to use overloaded operators in the main function and provides output results.
Operator Overloading: Operator– It is a symbol that indicates an operation. Arithmetic operators are + (add two numbers), - (subtract two numbers), * ( Multiply two numbers), / ( Divide between two numbers). At now, we will take an Addition ‘+’ Sign, its use of ‘+’ sign is 5+5=10 2.5+2.5=5
3.
Operator Overloadingmeans multiple functions or multiple jobs. In operator overloading the ‘+’ sign use of add the two objects. One of C++’s great features is its extensibility, Operator Overloading is major functionality related to extensibility. In C++, most of operators can be overloaded so that they can perform special operations relative to the classes you create.
4.
For Example,‘+’ operator can be overloaded to perform an operation of string concatenation along with its pre-defined job of adding two numeric values. When an operator is overloaded, none of its original meaning will be lost. After overloading the appropriate operators, you can use C++’s built in data types.
5.
Unary Operator -Operators attached to a single operand. (-a, +a, --a, ++a, a--, a++) Binary Operator - Operators attached to two operand. (a-b, a+b, a*b, a/b, a%b, a>b, a<b )
6.
return-type class-name:: operatorop(arg-list) { function body } EXPLANATION return type – It is the type of value returned by the specified operation. op - It is the operator being overloaded. It may be unary or binary operator. It is preceded by the keyword operator. operator op - It is the function name, Where operator is a keyword.
7.
INTRODUCTION In Binaryoperator overloading function, there should be one argument to be passed. It is overloading of an operator operating on two operands.