Procedural Programming with C++
Explainer
Two Functions, One Name: Overloading in C++
C++ lets you write three functions all called print. How does it choose?
Quick check · tap an answer to continue
Lesson notes
Key points
- Function overloading means defining several functions with the same name but different parameter lists in the same scope.
- At compile time, overload resolution matches the argument types in each call to the best fitting parameter list.
- A different return type alone is not enough, so int f(int) and double f(int) cause a compile error.
Definitions
- Function overloading
- Same function name, different number or types of parameters; the compiler picks one per call.
Takeaway: Overloads differ by parameters, never by return type alone.
Quick check: Which pair is NOT a valid overload?
- f(int) and f(double)
- f(int) and f(int, int)
- int f(int) and double f(int)
OverloadingOverload resolutionReturn type rule
Lessons like this, for your syllabus.
Short narrated study videos written for your course, level and exam. Free to start.
Get lessons for your own syllabus