-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperatorOverloading.cpp
More file actions
56 lines (38 loc) · 1.56 KB
/
OperatorOverloading.cpp
File metadata and controls
56 lines (38 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// See (Operator Oveloading theory.png)
// Example:
// + ----- The built in data type used to add integers i.e, 5 + 6 = 9
// Now, for e.g. we can also use + operator to add objects of a user defined class i.e, obj1 + obj2
// If we overload the + operator then:
// (1) can be used to add integers
// (2) can be used to add objects
// in the same program
// We use opearator function to overload operators
//****************************************************************************************************************
// SYNTAX:
//(For outside the class)
// return-type class-name::operator op(arguement list) //(op replaces by opearator +,_ etc)
// {
// body
// }
//(For inside the class)
// return-type operator op(arguement list) //(op replaces by opearator +,_ etc)
// {
// body
// }
//****************************************************************************************************************
// UNARY OPERATOR (1 operand) --- a++
// For unary opearator overloading
// E.G.
// If class member:
// test opearator +()
// If friend function (outside the class):
// test opearator +(test)
//*****************************************************************************************************************
// BINARY OPERATOR (2 operand) --- a+b
// For binary operator overloading
// E.G.
// If class member:
// test opearator +(test)
// If friend function (outside the class):
// test opearator +(test,test)
//******************************************************************************************************************