TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  OLC#016Checked automatically with code checker

Synopsis:Do not re-declare a visible name in a nested scope
Severity Level:2
Category:Object Life Cycle


This "shadowing" is almost always done inadvertently and can lead to hard to trace bugs.


int i = 1;
void f()
	int i = 2;	
	int j = i;   // Violation 

Exception: In case a method parameter has the same name as a field then the following construction can be used: this.x = x


int i = 1;
void f(int i)
	this.i = i; // No violation	
	int j = i; // However, this again is a violation!

See also [INT#026] for a related issue in the context of derived classes.