“Making New Friends”
summary
Shows a concrete technique: put non-member operator definitions inside a class template as friend functions so each instantiation manufactures its own friend, avoiding huge numbers of overload templates and restoring implicit conversions that template argument deduction would otherwise block. Demonstrates with a templated rational type, reproduces mean/median examples, traces compiler diagnostics across GCC/MSVC, explains the in situ definition trick and how argument-dependent lookup locates the generated operators.
AI-written summary · about
chapters (12)
- 0:00Introduction to friendship
- 1:03What is friendship in C++
- 8:03Friendship for operator overloading
- 16:36Rational number class example
- 21:00Rational class as a template
- 27:22Template conversion issues
- 31:29Compiler compatibility problems
- 40:28Making new friends idiom
- 47:01In situ friend definitions
- 52:55Fixing template conversion issues
- 58:13Friendship to deny membership
- 1:00:20Summary and references
