Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'                constructor-inh/inheriting-constructors-cpp11.cc - Attempting to inherit constructors - success.Lecture 5 - slide 4 : 40
Program 7

// Single inheritance - C++11 variant.
// Illustrates how it is possible to inherit the constructors from Base. C++11.

#include <string>

using namespace std;

class Base{
private:
  int i;
  string s;

public:
  Base(): i{0}, s{string("Hi")}{
  }

  Base(int i): i{i}, s{string("Hi")}{
  }

  Base(int i, string s): i{i}, s{s}{
  }
};

class Derived: public Base{
  // No state in Derived
public:
  using Base::Base;                // A using declaration:
                                   // Inherit the constructors from Base (!!)
                                   // The C++ Programming Language, 4ed, 20.3.5.1 (page 594).
};

int main(){

  Derived d1,                      // OK
          d2(5),                   // OK
          d3(6, string("AP"));     // OK
}