c++default-arguments

Where to put default parameter value in C++?


What's the place for the default parameter value? Just in function definition, or declaration, or both places?


Solution

  • Default parameter values must appear on the declaration, since that is the only thing that the caller sees.

    EDIT: As others point out, you can have the argument on the definition, but I would advise writing all code as if that wasn't true.