#include<iostream>
using namespace std;
class a
{
int x;
int y;
public:
void get_xy(int x,int y)
{
this->x=x;
this->y=y;
}
friend int operator=(a,a);
};
int operator=(a a5,a a6)
{
if(a5.x==a6.x&&a5.y==a6.y)
{
return(1);
}
else
{
return 0;
}
}
int main()
{
a a1,a2;
a1.get_xy(5,4);
a2.get_xy(5,4);
if(a1=a2)
{
cout<<"y"<<endl;
}
else
{
cout<<"n"<<endl;
}
return 0;
}
I am trying to overload the assignment operator=
by means of using a friend
function and stuck with error in attached screen shot. However when I overload it with a member function it works as expected. The code is posted above.