Where to put default parameter value in C++?

Thomson picture Thomson · Feb 14, 2011 · Viewed 204.7k times · Source

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

Answer

Marcelo Cantos picture Marcelo Cantos · Feb 14, 2011

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.