#include <iostream.h>
#include<conio.h>
class Num
{
friend Num operator+(Num ob, int i);
friend Num operator+(int i, Num ob);
int count;
public:
Num(int cc=0)
{
count=cc;
}
Num& operator=(int i);
void Show()
{
cout<<count<<endl;
}
};
Num& Num::operator=(int i)
{
count=i;
return *this;
}
Num operator+(Num ob, int i) // This handles ob+int.
{
Num temp;
temp.count=ob.count+i;
return temp;
}
Num operator+(int i, Num ob) // This handles int+ob ..
{
Num temp;
temp.count=ob.count+i;
return temp;
}
void main()
{
clrscr();
Num obj;
obj=10;
obj.Show();
obj=10+obj;
obj.Show();
obj=obj+ 12;
obj.Show();
getch();
}
Output:
10
20
32