Re: method hiding

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Sankar Nemani (snemani_at_nospamlumedx.com)
Date: 09/28/04


Date: Tue, 28 Sep 2004 11:14:37 -0700

Thanks Doug.
Is the behavior same if the the foo in class B was marked virtual? It seems
like the using declaration brings down all the foos that are declared in
class B if there were more than one. Can some foos be virtual and others
non-virtual? Is there a selective way of bringing down only a particular
foo?
By multiple foos I mean multiple methods that have the same name "foo" with
different signatures.

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:qg3jl0tq5shera3ima47pabuc9ncsguig0@4ax.com...
> Sankar Nemani wrote:
>
> >The 4th line in my main method in the code below does not compile.
> >Isn't there a way to overload a base class method in the derived class in
C++?
> >I know C#, java and VB.NET allow this.
> >TIA
> >Sankar Nemani
> >class B
> >{
> >public:
> > void foo(){}
> >
> >};
> >
> >class D: public B
> >{
> >public:
> > void foo(int i){}
> >};
> >
> >void main()
> >{
> > B *b = new B();
> > D *d = new D();
> > b->foo();
> > d->foo(); //does not compile
> >}
>
> You need to employ a using-declaration:
>
> class D : public B
> {
> public:
>
> // Bring all B::foo into the scope of D.
> using B::foo;
>
> void foo(int i){}
> };
>
> --
> Doug Harrison
> Microsoft MVP - Visual C++



Relevant Pages

  • Re: A description of function parameters
    ... In the declaration it's really just commentary: A name that never gets used and could just as well have been omitted or replaced with another. ... You could have written the declaration as `void foo;' or as `void foo;' with exactly the same effect. ... The parameter exists and has its value when foo() starts to execute, and it continues to exist until fooreturns or otherwise ceases to execute. ...
    (comp.lang.c)
  • Re: pass by Reference/value ???
    ... > void foo ... this would be called "passing by reference". ... foo receives a local copy of s and any changes that it makes to s only ... Since s is a pointer, a variable storing the address of s is a pointer to ...
    (comp.lang.cpp)
  • Re: Building extensibility into an API
    ... otherwise of "building extensibility into an API". ... Now maybe you think of some cool improvement to foo that you could make, ... foo_v2(int bar, char *baz, long double newparam); ... Each function you write takes an unused void * parameter. ...
    (comp.lang.c)
  • Re: Library bug or my fault?
    ... compiled using ARM/Linux cross-compiler and run on an ARM9 target. ... void memcpy ... 29 void cp(const Foo *foo) ... 31 Bar bar; ...
    (comp.lang.c)
  • Re: Void function returns value
    ... "The value of a void expression (an expression that has ... void foo() ... I knew the compiler needs a function pointer, ...
    (comp.std.c)