5

Is it possible to call the virtual function foo( int ) from B without using what is done in comment ?

class A {
public: 

    virtual void foo ( char * ) {
    }

    virtual void foo ( int ) {
    }
};

class B : public A {
public:

    void foo ( char * ) {
    }

    //void foo ( int i ) {
    //  
    //  A::foo(i);
    //}
};

B b;
b.foo(123); // cannot convert argument 1 from 'int' to 'char *'
2
  • 1
    Please fix the indenting..... the declaration of virtual void foo(int) on first glance appears to be the body of virtual void foo(char *). Compilers may not care about odd formatting, but humans do.... Commented Sep 11, 2014 at 19:45
  • 1
    @AndreKostur FWIW, the weird indent of foo overloads was introduced by an editor, not by the OP. Commented Sep 16, 2014 at 6:24

1 Answer 1

8

Yes, it is possible. The problem here is that the function B::foo(char*) hides the name of the inherited function A::foo(int), but you can bring it back into scope of B with a using declaration:

class B : public A {
public:

    void foo ( char * ) {
    }

    using A::foo;
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.