• Advertisement

Archived

This topic is now archived and is closed to further replies.

Restricted friend

This topic is 5953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When a class declares another class as "friend" the other class could access all of it''s private and protected members. Is there a way to allow the other class to access only certain members not all of it?

Share this post


Link to post
Share on other sites
Advertisement
I can''t think of any way that it''s possible, without playing some sort of inheritance trick. I doubt that it''s worth the effort. When you declare another class as a friend, that implies that the 2 classes go naturally together... which in turn implies that you have control over both classes, so encapsulation from each other is less important than encapsulation of the 2 classes from others. So my opinion is that it''s not generally worth worrying about.

Share this post


Link to post
Share on other sites

  • Advertisement