hit counter

Timeline

My development logbook

Item 19: Differentiate Among Member Functions, Non-member Functions, and Friend Functions

Summary:

Virtual functions must be members. If f needs to be virtual, make it a member function of C.

operator>> and operator<< are never members. If f is operatorĀ» or operatorĀ«, make f a non-member function. If, in addition, f needs access to non-public members of C, make f a friend of C.

Only non-member functions get type conversions on their left-most argument. If f needs type conversions on its left-most argument, make f a non-member function. If, in addition, f needs access to non-public members of C, make f a friend of C.

Everything else should be a member function. If none of the other cases apply, make f a member function of C.