A helper function is a non-member function that belongs to a class:
Point operator+(const Point& lhs, const Point& rhs) { return Point(lhs.GetX() + rhs.GetX(), lhs.GetY() + rhs.GetY()); }
- Avoid helper functions (except operator functions) at file scope in header (.h) files [1]
- Avoid helper functions with external linkage (including operator functions) in implementation (.cpp) files [1].
- Use namespaces to associate helper functions with the class they work on [2]
- Use helper functions for symmetric operators [3], for example operator+ and operator-
- John Lakos. Large-Scale C++ Software Design. 1996. ISBN: 0-201-63362-0. Chapter 2.3.2
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 18.5. Advice. page 548: '[7] Use namespaces to associate helper functions with "their" class'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 18.5. Advice. page 548: '[8] Use nonmember functions for symmetric operators'