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

Rule:  OLC#016Checked automatically with code checker

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


Description:

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

Example1:

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

Example2:

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.