In article <dM********************@pipex.net>,
sg*******@dNiOaSl.PpAiMpPeLxE.AcSoEm says...
[ ... ]
Why is it supposed to be like that, out of interest? What's the problem
with/disadvantage of not hiding base functions with the same name?
First, it's inconsistent with the rest of the language. For example:
int my_f() {
float a;
{
int a;
a = 0.0;
}
}
Here, the assignment is clearly to the int, even though the float is
a better fit with the type of '0.0'.
Let's assume we changed the rules, and considered this an assignment
to the float. The second major problem can be seen by adding 'double
a' (or 'extern double a') outside the function. Now, even though the
function itself hasn't changed at all, the meaning of the assignment
has changed completely -- it's an assignment to a different variable
entirely.
This also interacts with another rule in C++: first it resolves
names, then it checks access. That means (for example) if you add a
variable in a base class, it participates in overload resolution the
same whether it's private, public or protected. IOW, adding almost
any name in the base class would potentially affect the results in
all derived classes, even if the base class name as private, so the
derived classes couldn't access it.
Such a change would make it nearly impossible to maintain the base
class. Nearly any change in the base class would require intimate
knowledge of all derived classes. A seemingly minor change in the
base class might completely change the meaning of code in some
derived classes, while rendering others completely illegal.
--
Later,
Jerry.
The universe is a figment of its own imagination.