Free function versus member function

see this question: Effective C++ Item 23 Prefer non-member non-friend functions to member functions
and also C++ Member Functions vs Free Functions

You should prefer free functions, in the extent that it promotes loose coupling.

Consider making it a member function only if it works on the guts of your class, and that you consider it really really tied to your class.

It is a point of the book 101 C++ coding standards, which states to prefer free function and static function over member functions.

Altough this may be considered opinion based, it allows to keep class little, and to seperate concerns.

This answer states: “the reason for this rule is that by using member functions you may rely too much on the internals of a class by accident.”

Leave a Comment