List of operators that cannot be overloaded.
Increment the time using ++
Decrement the time using ++
Add two object using “+” operator with friend function
class distance (feet,inches) with “+” operator
class distance (feet,inches) with “+” operator with friend function
class distance (km,m) with “+” operator
class distance (km,m) with “+” operator with friend function
class distance (m,cm) with “+” operator
class distance (m,cm) with “+” operator with friend function
class distance (km,m,cm) with “+” operator
class distance (km,m,cm) with “+” operator with friend function
class distance (km,m,cm,mm) with “+” operator
class distance (km,m,cm,mm) with “+” operator with friend function
class time(hh,mm,ss) with “+” operator
class time(hh,mm,ss) with “+” operator with friend function
class complex(real,ing) with “+” operator
class complex(real,ing) with “+” operator with friend function
class string(str) with “+” operator
class string(str) with “+” operator with friend function

Example:19
Declare a class named “distance” with attributes as hh, mm, ss. Take input for two objects calculate and print their sum using overloaded binary operator “+” with friend function.

```//Add two time objects
//using friend function

#include<iostream>
#include<conio.h>
using namespace std;
class time
{
private:
int h,m,s;
public:
void show();
friend time operator+(time t1,time t2);
};
{
cout<<"enter h,m and s ";
cin>>h>>m>>s;
}
void time::show()
{
cout<<h<<" : "<<m<<" : "<<s<<endl;
}
time operator+(time t1,time t2)
{
time t;
t.h=t1.h+t2.h;
t.m=t1.m+t2.m;
t.s=t1.s+t2.s;
if(t.s>=60)
{
t.m=t.m+t.s/60;
t.s=t.s%60;
}
if(t.m>=60)
{
t.h=t.h+t.m/60;
t.m=t.m%60;
}
return(t);
}
int main()
{
time e1,e2,e3;
e1.show();e2.show();
e3=e1+e2;//e3=operator+(e1,e2);
e3.show();
getch();
return(0);
}

```

Output:

enter h,m and s 2 5 36
enter h,m and s 4 25 12
2 : 5 : 36
4 : 25 : 12
6 : 30 : 48

Example:20
Declare a class named “complex” with attributes as real and img. Take input for two objects calculate and print their sum using overloaded binary operator “+”.

```//to add two comples numbers
#include<iostream>
#include<conio.h>
using namespace std;
class complex
{
private:
int real,img;
public:
void show();
complex operator+(complex c);
};
{
cout<<"Enter values of real and img ";
cin>>real>>img;
}
void  complex::show()
{
if(img>=0)
cout<<real<<"  +i  "<<img<<endl;
else
cout<<real<<"  -i  "<<img*-1<<endl;
}
complex complex::operator+(complex c1)
{
complex t;
t.real=real+c1.real;
t.img=img+c1.img;
return(t);
}
int main()
{
complex e1,e2,e3;
e1.show();e2.show();
e3=e1+e2;//e3=e1.operator+(e2);
e3.show();
getch();
return(0);
}
```

Output:

Enter values of real and img 10 25
Enter values of real and img 3 6
10 +i 25
3 +i 6
13 +i 31

Example:21
Declare a class named “complex” with attributes as real and img. Take input for two objects calculate and print their sum using overloaded binary operator “+” with friend function.

```//to add two comples numbers
//Using friend function
#include<iostream>
#include<conio.h>
using namespace std;
class complex
{
private:
int real,img;
public:
void show();
friend complex operator+(complex c1,complex c2);
};
{
cout<<"Enter values of real and img ";
cin>>real>>img;
}
void  complex::show()
{
if(img>=0)
cout<<real<<"  +i  "<<img<<endl;
else
cout<<real<<"  -i  "<<img*-1<<endl;
}
complex operator+(complex c1,complex c2)
{
complex t;
t.real=c1.real+c2.real;
t.img=c1.img+c2.img;
return(t);
}
int main()
{
complex e1,e2,e3;
e1.show();e2.show();
e3=e1+e2;//e3=operator+(e1,e2);
e3.show();
getch();
return(0);
}
```

Output:

Enter values of real and img 25 9
Enter values of real and img 3 -5
25 +i 9
3 -i 5
28 +i 4

Important Pages