OOP_Lecture_8(Operator Overloading and Freind Fun)
OOP_Lecture_8(Operator Overloading and Freind Fun)
------------------------------------------------------
Lecture Topic: Operator Overloading and Friend Function
------------------------------------------------------
Instructor: Muhammad Aizaz Akmal
------------------------------------------------------
Lecture Oultine
0:Recape of previous Lecture
1:Operator Overloading
-What is operator Overloding
-Function Overlaod(function with same name but different parameter list)
void fun(int i);
void fun(string name);
void fun(int i, float j);
void fun(int i, float j);//Error redefination of function
-default operator support on object
asignment operator (=), dot operator (.)
Distance d1(10,2.5);
Distance d2(20,3.9);
Distance d3 = d2 + d1;
int i,j,k;
i=5;
j=10;
k=i+j;
-Operator Overloading is facility that allow the programmar to perform
operator on the object according to provided specification.
Distance d1(10,2.3);
++d1;
int& operator[](int i)
{
if(i>=size)
{
cout<<"index out of bound"<<endl;
return NULL;
}
else
return arr[i];
}
2:Friend Function
- Non member function that allowed to access the data members of class
both public and private after declaring them as a freind in a class.