"Tron Thomas" <tron.thomas@verizon.net> wrote in message
news:a4171f97.0411081546.32a5e466@posting.google.c om...[color=blue]
> Under the right compiler the following code:
>
> class Base
> {
> public:
> virtual void Method(int){}
> };
>
> class Derived: public Base
> {
> public:
> virtual void Method(float){}
> };
>
> will produce a warning such as:
>
> 'Derived::Method(float)' hides virtual function 'Base::Method(int)'
>
> This warning can be eliminated by adding the statement:
>
> using Base::Method;
>
> to the derived class.[/color]
Yes, that's how C++ works, methods are hidden by names, not by full type.
The reason is purely practical. There is good explanation of why in
Effective C++ (I think), but the basic idea is that in C++ you can have
pretty complex inheritance patterns that could pull lots of overloaded
functions with almost same argumnets in the single leaf class, not really
"telling" the developer about it. He then can occasionally call a wrong
function, not knowing about it's existence somewhere deeply in the
inheritance lattice and then spend a lot of time debugging this problem
And using "using" directive is exactlhy the prescribed solution. It was
believed that to the developer explicitly pulling overloaded names that he
needs to the child classes will cost him less than navigating the classes
hierarchy in case of an error trying to identify what has gone wrong.
[color=blue]
>
> This issue with methods being hidden does not exist in other languages
> such as Java.[/color]
That's because in Java all methods are virtual and there is no multiple
inheritance, hence the abovementioned tradeoff did not appear relevant to
Java designers.
[color=blue]
> What is the reason that derived methods can potentially hide base methods
> in C++?[/color]
Rgds
d
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com