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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. C++ Course

Lesson 2 of 45 · C++

Lesson 10: Function Overloading

Duration: 8 min

Function Overloading\n\nC++ 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.\n\n---\n\n## Example: Overloading based on parameter types\ncpp\nvoid print(int i) {\n std::cout << \"Integer: \" << i << '\\n';\n}\n\nvoid print(double d) {\n std::cout << \"Double: \" << d << '\\n';\n}\n\nvoid print(const std::string& s) {\n std::cout << \"String: \" << s << '\\n';\n}\n\nint main() {\n print(42); // calls int overload\n print(3.14); // calls double overload\n print(std::string(\"hi\")); // calls string overload\n return 0;\n}\n\n\nPitfall: If you add void print(long l); and call print(42);, the compiler may be ambiguous because both int and long are viable.\n\n> Tip: Use the explicit keyword on single‑argument constructors to avoid unintended implicit conversions.\n\n---\n\n<Alert type="warning">You cannot overload on return type alone; the return type is not considered in overload resolution.

Previous: Lesson 1: Introduction to C++Next: Lesson 11: Arrays