October 2004
Intermediate to advanced
240 pages
6h 22m
English
Avoid membership fees: Where possible, prefer making functions nonmember nonfriends.
Nonmember nonfriend functions improve encapsulation by minimizing dependencies: The body of the function cannot come to depend on the nonpublic members of the class (see Item 11). They also break apart monolithic classes to liberate separable functionality, further reducing coupling (see Item 33). They improve genericity, because it’s hard to write templates that don’t know whether or not an operation is a member for a given type (see Item 67).
Use this algorithm to determine whether a function should be a member and/or friend:
// If you have no choice then you have no choice; make it a member ...