Tuesday 31 March 2015

Program to Overload == operator

#include <iostream.h>
class dev
{
int a,b;
public:
dev(int x, int y)
{
a = x;
b = y;
}
int operator==(dev o)
{
if((a == o.a) && (b == o.b))
return 0;
else
return 1;
}
};
void main()
{
dev A(3,2), B(2,4);
int x = A == B;
if(x == 0)
cout<<”The content are same”<<endl;
else
cout<<”The content are not same”<<endl;
}

No comments:

Post a Comment