Re: method hiding
From: Sankar Nemani (snemani_at_nospamlumedx.com)
Date: 09/28/04
- Next message: Vladimir_petter: "Re: newbee: trouble w/ try{} catch{}"
- Previous message: Victor Herrera: "Re: Visual C++ 6 and API"
- In reply to: Doug Harrison [MVP]: "Re: method hiding"
- Next in thread: Doug Harrison [MVP]: "Re: method hiding"
- Reply: Doug Harrison [MVP]: "Re: method hiding"
- Messages sorted by: [ date ] [ thread ]
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++
- Next message: Vladimir_petter: "Re: newbee: trouble w/ try{} catch{}"
- Previous message: Victor Herrera: "Re: Visual C++ 6 and API"
- In reply to: Doug Harrison [MVP]: "Re: method hiding"
- Next in thread: Doug Harrison [MVP]: "Re: method hiding"
- Reply: Doug Harrison [MVP]: "Re: method hiding"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|