Ok guys ! I'm trying to study operator overloading. which i found the toughest article in OOP :(
I tried a code for == operator overloading to check whether both arrays have same elements or not but it isn't working. Can anyone help?
Here is my code:
#include<iostream>
using namespace std;
class array
{
private:
int arr[5];
public:
array()
{
for (int i=0;i<5;i++)
arr[i]=-1;
}
input()
{
for(int j=0;j<5;j++)
{
cin>>arr[j];
}
}
show()
{
for(int k=0;k<5;k++)
{
cout<<arr[k]<<endl;
}
}
int operator ==(array a)
{
if(a.arr==a)
return 1;
else
return 0;
}
};
int main()
{
array obj1,obj2;
cout<<"enter five elements in array 1:"<<endl;
obj1.input();
cout<<endl<<"enter five elements in array 2:"<<endl;
obj2.input();
cout<<endl<<"elements in array 1 are: "<<endl;
obj1.show();
cout<<endl<<"elements in array 2 are: "<<endl;
obj2.show();
if(obj1==obj2)
cout<<"both arrays have same elements"<<endl;
else
cout<<"both arrays are different";
return 0;
}