今天写程序时发现,一个类的私有成员可以被相同类的其他对象访问到。我觉得这有些违背私有成员的初衷,不知道这样设计有没有其他用意。 这是我的事例程序: #include <stdio.h> class Object { public: Object(int initX) { x = initX; } static bool CompareX(Object obj1, Object obj2) { return obj1.x == obj2.x; } int GetX(Object obj) { return obj.x; } private: int x; }; int main() { Object obj1(10); Object obj2(20); if (Object::CompareX(obj1, obj2)) printf("EQUAL/n"); else printf("NOT EQUAL/n"); printf("X in obj1 is %i/n", obj2.GetX(obj1)); return 0; }