Operator Overloading with a class array

Hey ya'll,

I'm new to operator overloading and I'm stuck on implementing my comparison function in main. I created a menu that allows the user to enter info on great lakes. The user has the option to enter data for a lake and to compare lake objects to see if their surface area is equal or which is greater. I went ahead and created a bool function for operator comparison. I guess I'm not understanding how to compare the objects in my array without using getters. I'd like to compare them like, "if(object1 == object2)".

So far in the .h file I have created this:

1
2
3
4
5
6
7
8
9
10
bool LakeInfo::operator == (const LakeInfo &lakeObject)
{
    bool status = false;
    
    if(lakeArea==lakeObject.lakeArea)
    {
        true;
    }
    return status;
} 



inside of my main file I created an array of LakeInfo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void objectComaprison(LakeInfo arr[], int size)
{
    string userInput;
    
    cout<<"Enter which operator you'd like to use to compare your 
            objects.\n";
    cout<<"Your choices are (<,> or ==).\n";
    getline(cin, userInput);
    
    /*for(int i =0; i<size; i++)
    {}*/
    if(userInput == "==")
    {
       /* if(arr == arr)
        {
            //arr.print();
        }*/
            
    }
Last edited on
L7 has no effect - so you are always returning false. Just:

1
2
3
4
bool LakeInfo::operator == (const LakeInfo &lakeObject)
{
    return lakeArea == lakeObject.lakeArea;
} 

Topic archived. No new replies allowed.