Not sure why this is not working getName returns a string Th

Not sure why this is not working, getName returns a string.
The error I get is \"expression must have pointer-to-class type.

void Person::orderByName(Person **p1, Person **p2) {
   if(*p1 -> getName() > *p2 ->getName()) {
       Person *temp = *p1;
       *p1 = *p2;
       *p2 = temp;
   }
}

Solution

Since you are passing a double pointer to this function you can not access getName() like this. Try changing it like

(*p1)->getName()

In your case it was not working due to operator precedence.

Not sure why this is not working, getName returns a string. The error I get is \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site