Caffeinated Coder
Book an appointment
Lesson 16 · Classes

Operator overloading

In C++ an operator like + or == on your own class is a function call in disguise: the compiler turns a + b into operator+(a, b). Build a small Vec2 type with four operators, watch the values travel into each function and the result travel out, and learn when an operator should be a member, when it should be a free function, and which rules you cannot break.

12 min8 steps5 questionsIntermediate
Fig 16 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.