Hi, I am trying to overload == operator to compare objects like below.
class A
{
int a;
public:
A(int x) { a = x; }
bool operator==(const A& obRight)
{
if(a == obRight.a)
{
return true;
}
return false;
}
};
int main()
{
A ob(10), ob2(10), ob3(10);
if(ob == ob2) // This equality comparison compiles fine.
cout<<"Equal"<<endl;
if(ob == ob2 == ob3) //This line doesn't compile as overloaded
// == operator doesn't return object (returns bool)
cout<<"Equal"<<endl;
}
As i described above, i am unable to do multiple object comparison in a single line
like if(ob == ob2 == ob3)
using overloaded == operator through member function.
Should i overload using friend function ?