Hi,
I'm working on fixing issues/bugs in a legacy codebase.
I'd like to ask experts opinion on a decision I've made regarding a
function. I don't have my Scott Meyers at hand but I'm fairly sure he
mentions this issue.
consider virtual function;
void foo()
{
if (something)
{
do_x();
}
else
{
do_y();
}
}
Now for reasons we don't need to know in this post, do_x() is the
correct behaviour for the scenario I'm debugging. However as it stands
the code always goes to do_y();
I want to change the signature of the function to;
virtual void foo(bool myFlag = false);
I've also updated the other classes that override this virtual function
with the new default argument (no function hiding etc)..
Now in the code path that I'm interested in (to fix this bug), I call
foo(true). I make no changes to any other code, and so myFlag is always
false in that scenario.
The logic of the function now looks like;
void foo(bool myFlag = false)
{
if ((something) || myFlag)
{
do_x();
}
else
{
do_y();
}
}
Now this will work for me. However Scott Meyers (vaguely from memory) I
*think* says this is not a good idea. Would people out there agree? Is
this a recipe for disaster or a sound approach.
thanks much.
Graham