I know that you can reuse variable names in C++, but I'm wondering whether I should. I'm not talking about reusing the variable itself, like with global variables. I'm talking about declaring and using a variable with a certain name in one scope, and then declaring and using another variable with the same name in a different scope. For example:
void Func1(int b) { /* Code here. */ };
void Func2(int b) { /* Different code here. */ };
void main()
{
{
int a=1;
// Do stuff with this variable.
}
{
int a=5;
// Do different stuff with this variable.
}
int b=10:
Func1(b);
Func2(b);
}
It seems like doing this would allow for shorter variable names and allow copy and pasting of code without having to change the variable names, but it might cause confusion. Is there a style guide or generally accepted practice about when to do this?
I searched for a similar question to this and I couldn't find anything. I found some stuff about global variables, but that's not what I'm looking for.