When should you use a class vs a struct in C++?
Answers
Answered by
0
Without specific examples this is hard to decide. While friend isn't strictly necessary it does have its uses. If, as you claim, there are better alternatives then obviously use them, by simple definition of the word “better”. Or maybe the decision which solution is better isn't that clean-cut after all.
Personally, I prefer to avoid it when possible but I prefer to use it over method duplication: for example, I do not like to write a print method just to avoid making operator << a friend because I don't see the benefit of the duplicate method.
Similar questions
Computer Science,
6 months ago
English,
6 months ago
Physics,
6 months ago
Chemistry,
1 year ago
English,
1 year ago
Social Sciences,
1 year ago
Math,
1 year ago