friend / member function question

I have two instances of a class, and the first instance needs to access the data of the second. Can I make the data private, and still allow the member functions of the first instance to access the data of the other one? Is it possible to have a member function also be a friend function (and thus access the private data)? Or, should I just make the data public and avoid all the hassle?

Comments

  • : I have two instances of a class, and the first instance needs to access the data of the second. Can I make the data private, and still allow the member functions of the first instance to access the data of the other one? Is it possible to have a member function also be a friend function (and thus access the private data)? Or, should I just make the data public and avoid all the hassle?
    :

    friends can't access the private data. must be either public (friend not needed) or protected.
  • : I have two instances of a class, and the first instance needs to access the data of the second. Can I make the data private, and still allow the member functions of the first instance to access the data of the other one? Is it possible to have a member function also be a friend function (and thus access the private data)? Or, should I just make the data public and avoid all the hassle?
    :

    This link may help:
    http://www.faqts.com/knowledge_base/view.phtml/aid/16164/fid/163

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories