When should functions be member functions?

Scott Meyers has advocated that non-member functions often improve encapsulation:

Herb Sutter and Jim Hyslop also talk about this (citing Meyer’s article) in “Self-Sufficient Headers”

These ideas have been republished (in more refined form) in the 3rd edition of Meyer’s “Effective C++”, “Item 23: Prefer non-member non-friend functions to member functions “, and Sutter/Alexandrescu’s “C++ Coding Standards”, “44 – Prefer writing nonmember nonfriend functions”.

I think a lot of developers find this non-intuitive and maybe a little controversial.

Leave a Comment