This rule is Obsolete | |
Synopsis: | Use overloaded functions instead of default arguments |
Language: | C++ |
Severity Level: | 9 |
Category: | Parts of C++ to Avoid |
Description: |
Define a set of overloaded functions instead of using default arguments. The mechanism is more powerful than default arguments:
example: Instead of writing a function with a default argument: void // declaration; definition omitted PrintName( std::string name, bool uppercase = false); define a set of overloaded functions: inline void // definitions; declarations omitted PrintName( std::string name) { bool uppercase = is_local(name); // determine value missing arg PrintName(name, uppercase); // delegate to two arg version } void PrintName( std::string name, bool uppercase) { // actual implementation to print the name with specified case } |