devnotes.

Default Arguments and Inline Functions

C++ lets a function parameter supply a fallback value when the caller doesn't provide one, and offers a hint to the compiler for very small, frequently-called functions.

void greet(std::string name, std::string greeting = "Hello") {
    std::cout << greeting << ", " << name << "!\n";
}

greet("Rahim");              // uses the default -> "Hello, Rahim!"
greet("Karim", "Hi there");  // overrides the default -> "Hi there, Karim!"

inline int square(int x) {   // hints the compiler to substitute the call directly
    return x * x;
}

Default arguments must come after any parameters without defaults, and are resolved at the call site using whatever value the caller actually passed (or the default, when omitted) — the function itself doesn't need any special logic to handle the missing argument. Default arguments are a convenient, lightweight alternative to writing multiple overloads that all funnel into one implementation.

inline requests that the compiler substitute a function call with the function's actual body directly at the call site, avoiding the (small) overhead of a real function call — historically important for tiny, hot-path functions, though modern compilers routinely make this decision automatically regardless of the keyword, so inline's main remaining practical use is allowing a function to be defined (not just declared) identically in multiple .cpp files without a linker error, which matters for small functions defined directly in header files.

Default Arguments and Inline Functions in C++ | DevNotes