confused about the friend keyword
-
i understand that the use of the friend keyword allows you to get around access specifiers but im a little confused as to why, or when you would want to do this as opposed to just adding it as a regular function.
friend is useful when you build a set of classes that really work together but make more sense to keep as individual classes for organizational reasons. Some of the functionality they use between them should be non-public. Friend helps achieve that. Purists discourage the use of friend. However, that philosophy can lead to huge monolithic classes or exposed public methods that really shouldn't be used by everyone. I found it to be useful but I agree with some that it should be used sparingly.
-
friend is useful when you build a set of classes that really work together but make more sense to keep as individual classes for organizational reasons. Some of the functionality they use between them should be non-public. Friend helps achieve that. Purists discourage the use of friend. However, that philosophy can lead to huge monolithic classes or exposed public methods that really shouldn't be used by everyone. I found it to be useful but I agree with some that it should be used sparingly.