TITLE: "using" and overloading names (Newsgroups: comp.lang.c++.moderated, 20 Dec 97) JAFFE: Steve Jaffe (sjaffe@ml.com) > This rather annoying feature is called 'lexical hiding'; the bottom line > is that if you override (ie redefine) any one of a set of inherited > overloaded functions, you must redefine _all_ of them; otherwise, the > ones you do not redefine will be inaccessible from the derived class. > See, for example, Stanley Lippman, "C++ Primer", p. 402. SUTTER: herbs@cntc.com (Herb Sutter) (2nd ed?) Actually, Stan's example is slightly different. He's talking about inheriting from two base classes that have the same virtual function. (The solution is to use an intermediate base class to change the function's name, so that you don't lose the virtualness; I didn't see that solution on that page, but I didn't read around so maybe this solution was mentioned somewhere nearby.) Getting back to the original question, though: JAFFE: > BTW, I find this a good argument _against_ the somewhat popular idiom of > pairing set-get methods with a single overloaded name: eg instead of > setFoo(aFoo) vs getFoo(), using foo(aFoo) vs foo(); if a derived class > want's to alter one method (typically the 'set' method), it must > redundantly redeclare and redefine the 'get' method as well. SUTTER: This is a common misconception, but it's not really so. You just need to write a "using" declaration: struct Base { virtual void f( double, double ); virtual void f( int ); virtual void f( complex<double> ); }; struct Derived : Base { void f( int ); // override using Base::f; // bring other inherited functions into scope, // no need to redeclare or redefine }; See also GotW #5 at www.peerdirect.com/resources/gotw005a.html#Solution for more details.