Does this seem right?

Does this seem right?? Because if it is than I'm pretty much got Operator Overloading down.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Person{

friend bool operator&==(Person &prs){

if (*this->firstname == prs.firstname){

   if(*this->lastname == prs.lastname)
        
        return true;
}

           else 
               return false;
}
Last edited on
No response? yet.
this is a pointer. So you are dereferencing twice.
1
2
3
(*this).firstname
this->firstname
firstname

Why are you nesting the if?
No need to declare the method friend
Last edited on
what is this &==

and also:
The use of the friend keyword means that the function is a non-class member and you
should provide BOTH of the variables being tested for equality.
In this case it is easier to remove the friend keyword.
Yes I see that now.
Topic archived. No new replies allowed.