r/cpp • • Apr 19 '20

Default function arguments are the devil

https://quuxplusone.github.io/blog/2020/04/18/default-function-arguments-are-the-devil/
92 Upvotes

149 comments sorted by

View all comments

Show parent comment

2

u/anonymous23874 Apr 19 '20

The author isn't complaining about overload sets with multiple possible signatures, though. Just about trying to implement that overload set using default arguments in particular.

void myAPI(std::string_view name, bool advancedUsage);  // OK
void myAPI(std::string_view name) { return myAPI(name, true); }

// versus

void myAPI(std::string_view name, bool advancedUsage = false);

Same user experience for simple calls; fewer pitfalls for advanced usage.