HOME

Sunday, November 29, 2015

BINARY == OVERLOADING USING FRIEND FUNCTION

#include<iostream>
using namespace std;
class sample
{
    int a;
public:
    void getdata()
    {
        cout<<"ENTER VALUE"<<endl;
        cin>>a;
    }
    void display()
    {
        cout<<"VALUE = "<<a<<endl;
    }
    friend int operator==(sample &obj1, sample &obj2);
};
int operator==(sample &obj1,sample &obj2)
{
    if(obj1.a==obj2.a)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{
    sample s1,s2;
    s1.getdata();
    s2.getdata();
    if(s1==s2)
    {
        cout<<"BOTH VALUE IS EQUAL"<<endl;
    }
    else
    {
        cout<<"VALUE ARE NOT EQUAL"<<endl;
    }
    return 0;
}

No comments:

Post a Comment