Templates allow you to easily reuse duplicated code when classes or functions need to work with more than one type, but behave similarly for the different types. Some information on templates, including the use of friend within templates is available at http://www.cs.fiu.edu/~weiss/Deltoid/msvc_stl_3.html