4 ms·
I don't get what's unintuitive here? default parameters are caller's hint, it's even part of declaration - not definition (and it doesn't have to be the same i
by konstantinua00 3y ago
I don't get what's unintuitive here?
default parameters are caller's hint, it's even part of declaration - not definition (and it doesn't have to be the same in different files, it's not even ub - because it's literally hint for the caller when param isn't there)
"dynamic default parameters" would pin them to the function, which isn't the design
- Sebb767 3y agoTake this scenario: Rectangle *r = new Rectangle(); r->draw(); // calls Rectangle::draw(GREEN) Shape *s = *r; s->draw(): // calls Rectangle::draw(RED) Intuitively, you would not expect that a function changes its behavior when it's called from a pointer of a different type. I can easily see this leading to very a fun-to-reproduce-kind of bug.
- cryptonector 3y agoOTOH if you don't know what the type of `s` run-time type is then you might draw comfort from knowing that the parameter's default is that of `s` static type.