Hi all,
I'm busy coding up some classes now and I was wondering if there is any danger in using a variable name twice, if the variable is limited to local scope.
For instance, let's say I have the following piece of code:
class Foo
{
void function1( double variable1 )
{
double variable2;
double variable3;
variable2 = function2( variable2 );
}
double function2( double variable2 )
{
double variable1;
double variable3;
return( variable1 * variable2 ) ;
}
};
In this code, variable2 appears locally in function1 and also as the definition of an input parameter for function2. Is this dangerous? Should the argument of function2 have another variable name? Or is this a stable way to program in C++? The same goes for variable1. Variable3 is in this case a dummy variable that is declared in local scope in both function1 and function2. Is this dangerous? Should variable3 be called differently in one of the functions? Or does the fact that the scope is local take care of any possible conflicts?
Thanks a lot,
Kartik