@LB: No idea. I'm just a simple pencil sharpener. No, seriously, I admit that I didn't know you could do that. How is it possible? Aren't private members, well... private?
Any member function of a class can access all members of that class, regardless of 'privateness'.
Alternatively, your global version would not work that way (unless you make it a 'friend' of the class), because it has no access to private members.
OK, so if I understand this correctly, if an internal function, such as the overloaded equality operator above, references any instance of the same class, I can access the private members of the referenced instance?
#include <iostream>
class myClass {
public:
booloperator==(const myClass& rhs) { return anInt == rhs.anInt; }
myClass(int A) : anInt(A) {}
private:
int anInt;
};
int main() {
myClass a(6), b(6), c(10);
if (a == b) std::cout << "a equals b!" << std::endl;
if (a == c) std::cout << "a equals c!" << std::endl;
if (b == c) std::cout << "b equals c!" << std::endl;
return 0;
}