Content deleted Content added
4-space indention for Java |
dedent code examples |
||
Line 41:
For example, the parameter "foo" shadows the local variable "foo" in this common pattern:
<source lang="java">
}
}
</source>
Name masking can cause [[Function overloading#Complications|complications in function overloading]], due to overloading not happening across scopes in some languages, notably C++, thus requiring all overloaded functions to be redeclared or explicitly imported into a given namespace.
Line 62:
For example, in this code:
<source lang="cpp">
public:▼
setX(x);▼
setY(y);▼
void setX(double newx) { x = newx; }▼
Point(double x,
}
}
</source>
within the <tt>Point</tt> constructor, the class variables <tt>x</tt> and <tt>y</tt> are [[Variable shadowing|shadowed]] by local variables of the same name. This might be alpha-renamed to:
<source lang="cpp">
void setX(double newx) { x = newx; }▼
▲ void setY(double newy) { y = newy; }
}
void setY(double newy) { y = newy; }
}
</source>
In the new version, there is no masking, so it is immediately obvious which uses correspond to which declarations.
|