[Solved] How can I compare the a variable in different instances of the same class?


Your comparison code is fine. The problem is that you’re not calling the function correctly. You need to call the member function through an object. Otherwise, how will it know that it should be comparing with pepper?

if (pepper.sameAge(salty)) {
    // do something
}

This is basic to all object-oriented programming — methods are called through objects.

1

solved How can I compare the a variable in different instances of the same class?