Consider
int biff;
int var;
struct Var {
int var;
void foo(int var) {
biff = var;
}
};
Which var is used in the assignment?
Sure, a good C++ programmer knows the rules. But it can be hard to tell in a large program.
You can disambiguate for the member
biff = this->var;
or the global
biff = ::var;
But so far as I know there is no syntax for arguments. I often use a naming convention
void foo(int arg_var) {
this->var = arg_var;
}
This is not unlike the widespread convention of saying
void foo(int arg_var) {
m_var = arg_var;
}
although I deprecate this because m_var for member names can lie - there may be a global of that name. Whereas this-> is not much bigger, and has the compiler check your meaning.
Perhaps there should be sigils, like this-> and ::, for arguments and locals?
--
Late addition, 5/25/2012:
I dislike extra typing. Plus, occasionally I will do a refactoring where an arg or a global becomes a local or a member. Sometimes I want such refactorfings to show up in history diffs, sometimes not.
Here's an interesting possibility: have the build or ODE system annotate the code with a hidden sigil (which I would suggest being XML, something like
var.
Have the IDE warn if an edit would change the implicit sigil. Much as GCC warns if an inner scope hides an outer scope's name.