Tuesday, 6 March 2018

Operator Overloading

Adding Two Objects

"Nice One Program"

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class rv{ public:
int val;
rv(){ val=1;

}
rv operator +(rv ss)
{     cout<<"func called Will returb object\n";
rv temp;
temp.val=val+ss.val;
return temp;
}};

void main()
{       clrscr();
rv obj1,obj2,obj3;

obj3=obj1+obj2;
cout<<"\n Value of obj3: "<<obj3.val;
getch();
}


No comments:

Post a Comment