Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Lesson 10: Function Overloading | C++ Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. C++ Course

Lesson 10 of 45

·C++

Lesson 10: Function Overloading

8 min

Course progress22%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Overload resolution rules for functions
  • Ambiguities and best‑match selection
  • Overloading operators vs. functions
  • Limits of overloadable functions

Function Overloading

C++ allows multiple functions with the same name but different signatures (parameter types, number, or const‑qualifiers). Overload resolution picks the best match based on the arguments supplied. Ambiguities arise when two overloads are equally viable.


Example: Overloading based on parameter types

void print(int i) {
    std::cout << \"Integer: \" << i << '\
';
}

void print(double d) {
    std::cout << \"Double: \" << d << '\
';
}

void print(const std::string& s) {
    std::cout << \"String: \" << s << '\
';
}

int main() {
    print(42);           // calls int overload
    print(3.14);         // calls double overload
    print(std::string(\"hi\")); // calls string overload
    return 0;
}

Pitfall: If you add void print(long l); and call print(42);, the compiler may be ambiguous because both int and long are viable.

Tip: Use the explicit keyword on single‑argument constructors to avoid unintended implicit conversions.


<Alert type="warning">You cannot overload on return type alone; the return type is not considered in overload resolution.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from C++ CourseBrowse activities
Previous lessonLesson 9: Parameter Passing – By Value and By ReferenceContinue to lesson 11Lesson 11: ArraysBack to C++ Course curriculum