advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Certain pundits frown at friend declarations because they allegedly violate encapsulation, allowing external entities to access non-public members of a class. How would you refute this claim? Tell us in the C++ Forum.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
Average Rating: 3.9/5 | Rate this item | 7 users have rated this item.
 

Taming Friends for Use in Templates

You can declare classes and functions friends, but the unfriendly syntax may bewilder you—particularly if you're using them in templates. Learn some simple guidelines and rules to tame friend declarations and make them do precisely what you want them to.  


advertisement
any design patterns and programming idioms rely on the use of friend declarations. However, when friend declarations are used in templates, the obfuscated syntax can bewilder even expert programmers. This month's solution demonstrates how to fine-tune friend declarations, while overcoming the syntax barrier at the same time.


How do you declare a template as a friend of another template? How can you distinguish between a specialization and a primary template in such declarations? What if you need to declare an asymmetric overloaded operator as a friend?


Follow the guidelines and rules set forth in this solution.

  Next Page: Non-template Friends
Page 1: IntroductionPage 3: Befriending Function Templates
Page 2: Non-template Friends Page 4: Aren't Friends Electric?
Please rate this item (5=best)
 1  2  3  4  5
advertisement