•
Sawtribaii PJrnle Pun.e Uni e:r Ii. r
I I
E
Ml
QJNo.
I I I I I I
TOiAL
I
11 I I 11
SPPU HUB,
1
r;cg;./ Q. No.
I fl. I I
+ A)' l>elinitto11 ol operator overloadi119·
- Operator ov:erJoading is a feature irJ programming languages that allows you to
redefi»e the be havior of certair, operators (.such as
or o.bjects.
·*
+J I) for custom dato types
J
-T�is assign more than· one operotion on 0'1 some operator known as operat,o•r
overloading.
- To ad'Jieve, d operator overloading we hav:e to write a .special function known as
operatorO.
Sgntox
Retum_tgpe opera·tor .symbol' (argument Ii.st) [
Body )'
RMl:es For overl'oading operator:
- Or,lg exi.stir,9 operators can be .overloaded',
- The basic meanir,g ,of the operator can not be changed.
- Overloaded operators must follow the syntax of origina} operator. For example for
Binary operator ,operandi ,operator operar,d2 is the syntax and this can no·t be
Changed .during overl'oadin9 .
- Overloaded operators must hav:e at }east one operar,d that is of user deflned type.
- Binary arithmetic ope,rators(+1 * and I) must return a value.
-,
- t.,)her1 binary operators ov:erloaded through Q member functfonJ the left hand
Operand must be an object ,of relevant da.ss.
- Binary operators overloaded through a member fun,ction must take ,o:ne expJicit
Argument.
- Binary ,operators overJoade·d through friend function tak,e.s two arguments.
- Unary operators overl'oaded through a member function must take ino ,explicit
Argument and no return vaJu.e.
- Unary opera·tors overloaded thr;ough· friend function takes one ,explidt argument.