On 12 Oct, 22:18, Dan Noland <nolan...@gmail.comwrote:
>
Thanks, I just found a similar explanation in section 19.3.1 of
Lippman and Lajoie. It seems strange that the shadowing is done by
function name rather than function prototype, but this works. Do any
language/compiler gurus know why this is the case?
YT,
Dan Nolandhttp://nolandda.org/
It's a safety measure against very difficult bugs.
Suppose you are using your preferred library in your project. This
library has a very deep and complex hierarchy, you create your class
subclassing from a class of this library:
class myclass : dialog_box
{
.... cut ...
void clear(long id);
};
Now suppose that somewhere in the library there is a class widget and
dialog_box is derived from that.
class widget
{
.... cut ...
void clear(int id);
};
and *you are not aware of the exsistance of widget::clear()* it can
happen in very big libraries, as example GUI libraries.
Now somewhere in your code you write:
myclass c;
c.clear(7);
Q: what member do you think compiler will call?
A: a conforming compiler will call _fortunatly_ your myclass::clear()
function, but if the hidden rule was not present the compiler would
have called widget::clear() instead.
If you don't know about widget::clear() finding the bug could span
from difficult to nightmare!
Proably who introduced such a rule in C++ was bitten by something like
this ;-)