RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


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.

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.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date