Re: Am I the only one mad here?
On Dec 6, 4:56 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Darko wrote:
[Classical problem concerning function hiding...]
Nothing in particular. It's the error in your code. You can
fix it by doing
b.A::f(4);
More likely, if the intent is to be able to call A::f with an
object of type B, he should add "using A::f;" to B. (I'm not
sure of the syntax. I've never wanted to do this.)
Note that this is often symtomatic of a bad design. In my
experience, about 90% of my derivation is directly from an
"interface", and once the object is constructed, the client
never uses anything but the interface. But there are certainly
exceptions (i.e. 90% isn't 100%).
Personally, it broke my C++ confidence.
Was there confidence to begin with?
As soon as you understand the difference between
"overloading", "hiding", and "overriding", you'll know what to
do. You also might want to learn about "name lookup",
although it's not really a simple topic.
Nothing in C++ is as simple as it could be. In many cases, it's
because of the C heritage. But in a few cases, like this one,
the "unexpected" behavior turns out to really be much more
useful in larger projects than the "intuitive" behavior would
be.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34