Page 152 - DCAP404 _Object Oriented Programming
P. 152
Unit 7: Operator Overloading
}; Notes
integer::integer()
{
val = 0;
}
integer::integer(int one)
{
val = one;
}
integer integer::operator+ (integer objb)
{
integer objsum;
objsum.val = val + objb.val;
return (objsum);
}
void integer::disp()
{
cout<< “value =”<< val<< endl;
}
void main()
{
integer obj1(11);
integer obj2(22);
integer objsum;
objsum = objl + obj2;
obj1.disp();
obj2.disp();
objsum.disp();
getch();
}
You should see the following output.
value = 11
value = 22
value = 33
LOVELY PROFESSIONAL UNIVERSITY 145