How to open hidden overload from base class?

Given this code:

class base {
public:
  string foo() const; // Want this to be visible in 'derived' class.
}

class derived : public base {
public:
  virtual int foo(int) const; // Causes base class foo() to be hidden.
}

How can I make base :: foo () visible to a derivative without replicating it with an overload of the dummy method that calls the base class? Does the usingtrick do, if so, where does it go, is that so?

class derived : public base {
public:
  virtual int foo(int) const;
  using base::foo;
}
+5
source share
2 answers

Sorry for the short answer, but yes. This exactly does what you want:

class derived : public base {
public:
  virtual int foo(int) const;
  using base::foo;
};

Also note that you can access the database even without using:

derived x;
string str = x.base::foo(); // works without using
+4
source

using . , . ( )

+1

All Articles