TITLE: non-member functions improve encapsulation (Source: Scott Meyers in C/C++ Users Journal, Feb 2000) Scott has an interesting article in print which advocates that non-member non-friend functions improve encapsulation for classes. He uses the following algorithm to determine where a function f gets placed: if (f needs to be virtual) make f a member function of C; else if (f is operator>> or operator<<) { make f a non-member function; if (f needs access to non-public members of C) make f a friend of C; } else if (f needs type conversions on its left-most argument) { make f a non-member function; if (f needs access to non-public members of C) make f a friend of C; } else if (f can be implemented via C's public interface) make f a non-member function; else make f a member function of C; His definition of encapsulation involves the number of functions which are impacted when private data members are changed. For more details in the full article see: http://www.cuj.com/archive/1802/feature.html _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com