Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:None
-
Message:Add an overloaded method to define [parameter name|parameter number n]
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Covered Languages:C, C++
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
Description
Setting method parameter defaults seems like a tidy way to make a method more usable. However, function pointers to methods with defaulted parameters can be confusing, because the function signature may not seem to match the call signature. Therefore, the use of multiple, overloaded methods is preferred.
Noncompliant Code Example
void HelloWorld (string name="World") { cout << "Hello " << name << endl; }
Compliant Solution
void HelloWorld (string name) { cout << "Hello " << name << endl; } void HelloWorld () { HelloWorld("World"); }
See also
- S3719
Attachments
Issue Links
- is implemented by
-
CPP-606 Rule: Default parameters should not be defined
-
- Closed
-
-
CPP-2975 S1712: Do not raise on template instantiations
-
- Closed
-
- is related to
-
CPP-3014 S1712: Rework the rule to allow benign default arguments
-
- Open
-
-
RSPEC-3719 Virtual functions should not have default arguments
- Active
- links to