Why can't an overridden virtual method view a version of overloaded base classes without explicitly defining scope?

I don’t understand why the compiler doesn’t like it, here is an example of a problem:

class A
{
public:
    virtual void Expand() { }
    virtual void Expand(bool flag) { }
};

class B : public A
{
public:
    virtual void Expand() {
        A::Expand(true);
        Expand(true);
    }
};

When I try to compile this, compiling A::Expand(true);fine but not copied Expand(true);gets this compiler error:

'B :: Expand': function does not accept 1 argument

+3
source share
2 answers

This is because, in addition to overriding the base, Expand()you also hide the base Expand(bool).

When you enter a member function in a derived class with the same name as the method from the base class, all methods of the base class with this name are hidden in the derived class.

( ), using:

class B : public A
{
public:
    using A::Expand;
    virtual void Expand() {
        A::Expand(true);
        Expand(true);
    }
};
+3

virtual . . , - Expand ( ), , .

using. using A::Expand; B:

class B : public A
{
public:
    using A::Expand;  
    virtual void Expand() { Expand(true); }
};
+4

All Articles