On Apr 7, 1:02*pm, Leigh Johnston <le...@i42.co.uk> wrote:
> On 07/04/2011 18:59, Christopher wrote:
>
>
>
>
>
> > On Apr 7, 12:29 pm, Leigh Johnston<le...@i42.co.uk> *wrote:
> >> On 07/04/2011 18:26, red floyd wrote:
>
> >>> On Apr 7, 10:12 am, Christopher<cp...@austin.rr.com> * *wrote:
> >>>> Where is the rule that explains why this will not compile? I've always
> >>>> expected this to work, but it would appear that I haven't run into
> >>>> this problem yet.
>
> >>>> To resolve the problem, do I really need to override every single
> >>>> method from the Base with the same name as the specific method I am
> >>>> interested in overriding? I have a good 20 of them in production code.
>
> >>> No. *Use "using" (see below).
>
> >>>> class Base
> >>>> {
> >>>> public:
> >>>> * * *virtual void Foo()
> >>>> * * *{
> >>>> * * *}
>
> >>>> * * *void Foo(int x)
> >>>> * * *{
>
> >>>> * * *}
>
> >>>> };
>
> >>>> class Derived : public Base
> >>>> {
> >>>> public:
> >>>> * * *void Foo()
> >>>> * * *{
> >>>> * * *}
>
> >>> * * * *using Base::Foo(int);
>
> >> That is ill-formed code; instead use:
>
> >> * * * * *using Base::Foo;
>
> >> /Leigh- Hide quoted text -
>
> >> - Show quoted text -
>
> > I don't really have the option of changing the anything where it is
> > called. That would be thousands of places in code that had already
> > been written before I cam aboard and I am sure the bosses would frown
> > on altering working stuff.
>
> > I am thinking of renaming the method I want to override to FooHelper.
>
> > I do wonder what the rule is though?..., so I can quote it in my
> > comments.
>
> You put the using declaration inside the derived class not where it is
> called; read replies more carefully.
>
> /Leigh- Hide quoted text -
>
> - Show quoted text -
Ok This works, but can you explain what that using directive is doing?
If I read the docs on the using directive, I'd expect these to be
equivalent:
class Derived : public Base
{
public:
using Base::Foo;
void Foo()
{
}
};
class Derived : public Base
{
public:
void Base::Foo() // This makes no sense and the compiler tells me
so
{
}
};
|