Can Someone Clarify Private for Me?

The C++ intro book I've been reading isn't very clear on exactly how private works, so I can see two possible interpretations. Either only an object can access its own private members/functions, or only a class can access its own private members/functions (but any object of that class can access the private members/functions of any other object of that class).

Basically, would this (pseudo)code work?

1
2
3
4
5
6
7
8
9
10
class foo {
 public:
  void bar1(foo&);
 private:
  void bar2();
};

void foo::bar1(foo& buddy){
  buddy->bar2();
}


That is to say, if I have two objects of type foo, a and b, can a use b's private stuff?
Last edited on
yes. you could have just compiled it, you know..
As long as line 9 is buddy.bar2();.
Topic archived. No new replies allowed.