How would I check a Node with multiple variables if it's values are the same as another node's values?

In my teacher's code, he has a snippet in his code where it goes:
 
  bool sameAs(Node* q) {return (data == q->data);} 


In my code, I want to have multiple variables. So instead of just data, I would have first, mid, last, and phone. It's hindering another of my function so I just wanted to see if what I'm writing is the equivalent and the problem isn't in that area.

My code is:
1
2
3
4
5
6
7
8
9
10
11
12
bool sameAs(Node* q){
 if(first == q->first){
    if(mid == q->mid){
      if(last == q->last){
        if(phone == q->phone){
return true;
        }
      }
    }
  } 
  
}


I would appreciate help. Apologies for the multiple posts.
Last edited on
Your compiler should warn you that it is wrong. If one of those conditions is untrue then you would return ... nothing.

It's also highly contorted. Try
1
2
3
4
bool sameAs(Node* q)
{
   return first == q->first && mid == q->mid && last == q->last && phone == q->phone;
}
Topic archived. No new replies allowed.