~/talk

The Art of C++ Friendship - The C++ Friend Function Explained

Talkat C++Online 2025 · 2025-02-26..02-28· [c-and-cpp]
slides:none on file

Concrete rules and examples for when friendship helps: friend grants full private/protected access but is not inherited, transitive, or mutual; use it for non-member customization points (streaming, arithmetic) to enable ADL and produce far shorter compile errors and faster name-lookup than sprawling overload sets. Alternatives shown: a constructor key to avoid broad friend access and an attorney–client idiom to expose only a make function. A hidden friend injection base-class pattern makes binary operators symmetric for templates and works in a units library.

AI-written summary · about

  1. 0:00Introduction
  2. 1:14What is a friend in C++
  3. 3:44Streaming operator problem
  4. 8:17Binary operators and getters
  5. 11:11Why friend keyword exists
  6. 12:39Friend access and coupling
  7. 14:05Who can be a friend
  8. 16:17Friend member functions
  9. 22:10Does friendship break encapsulation
  10. 26:26Rules of friendship in C++
  11. 29:18When not to use friends
  12. 33:38Friendship as strong coupling
  13. 34:41Secure session example
  14. 38:55Template friend functions
  15. 44:17Compile-time performance issues
  16. 46:25Hidden friend functions
  17. 50:03Recommendations for customization points
  18. 50:43Hidden friend pitfalls
  19. 53:14Hidden friend injection idiom
  20. 56:28Summary of friend usage
  21. 57:31Alternatives to friendship
  22. 57:52Conclusion and Q&A
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.