Classes C++

Hi, I am studying classes and I came across this question. Is it possible that two objects from the same class assess each other's private variables?If so, how can this be done? I've always thought that private means private. Thank you
Hi jshm, See Assess of members is depend on where you are going to use them.

for private: its limited to own class.
for public: its not limited to class , you can access them out side the class.

So form above point you can not access private members of object out side the class whether they are from or from diff no matters.

I hope its clear now.
Is it possible that two objects from the same class assess each other's private variables?
Yes. The access is limited to the class not the object

If so, how can this be done?
Like so:
1
2
3
4
5
6
7
8
9
10
11
class a
{
public:
  void Set(const a &b)
  {
    x = b.x;
  }

private:
  int x;
};
Topic archived. No new replies allowed.