Original Post
I was recently re-reading Effective C++ by Scott Meyers and I noticed one item that seems very strange to me upon examination: Item 23: Prefer non-member non-friend functions to member functions. This basically says that if you need to add a function that works on a class, it is better to make this function a non-member function than a member function. The reasoning behind this seems to be that if you used a member function, then you are not following the intent behind encapsulation. That is, a new member function will increase the amount of code that has access to the private variables of the class it belongs to where as a non-member function does not. This seemed to make sense at first, but if you take this item to the extreme, it seems to suggest that the best class design would be to make every class just have setter and getters for their private variables and then have any method that works on the class as a non-member function... which to me seems wrong. I was wondering what other people's take on this is. Do you just rely on gut instinct to make your decision? I originally started thinking of this more because I was looking at some math libraries and some libraries seem to prefer making the "cross product" function a member function of a "vector" class while others made it a nonmember function. Of course this is a trivial case, but this decision seems to come up quite a lot.