Reputation: 1903
Using ReSharper with C++17, and I enabled many of the warnings just to see what my project warns me about. I get this:
Declaring a parameter with a default argument is disallowed[fuchsia-default-arguments]
The code in question is the constructor:
class Point2D
{
public:
explicit Point2D(double x = 0.0, double y = 0.0);
};
I'm wondering why default arguments would be considered bad/poor/worthy of a warning? Does anyone have any code examples proving this a viable warning?
Upvotes: 5
Views: 1913
Reputation: 8968
There are several odd corner cases when it comes to default arguments on function parameters.
Here is a presentation from CppCon 2017 detailing a lot of tricky behavior. https://youtu.be/NeJ85q1qddQ
To summarize the main points:
Of course, for your case of a non-template constructor, they are fairly innocuous. It can’t be overridden or redeclared (although an out-of-line definition might cause you possible pain).
Upvotes: 6