Functions & Overloading in C++

From the C++ cheat sheet · Functions · verified Jul 2026

Functions & Overloading

Signatures, defaults, and overloads.

cpp
// Quick Reference
int add(int a, int b) { return a + b; }
int add(int a, int b, int c);       // overload
void greet(std::string name = "friend"); // default arg
💡 Overloads are chosen by argument types; return type alone cannot distinguish them.
⚡ Default arguments must be the trailing parameters and live on the declaration.
📌 Declare a prototype (or include its header) before calling a function.
🟢 Trailing return (-> type) pairs well with templates where the type depends on params.
functionsoverloading

More C++ tasks

Back to the full C++ cheat sheet