HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppCritical

Where to put default parameter value in C++?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
whereparameterputvaluedefault

Problem

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.

Context

Stack Overflow Q#4989483, score: 365

Revisions (0)

No revisions yet.