Monday, May 19, 2014

member functions VS non-member functions


    • Virtual functions must be members. If f needs to be virtual, make it a member function of class 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.

      0 Comments:

      Post a Comment

      Subscribe to Post Comments [Atom]

      << Home