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

// Attempting to inherit constructors - does not compile. C++11.
// Problems in this version. The next version of the program shows a convenient solution.

#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:
  Derived() = default;             // Means: We are happy with the default constructor


};

int main(){

  Derived d1,                      // OK
          d2(5),                   // Error: no matching function for call to 'Derived::Derived(int)'
          d3(6, string("AP"));     // Error: no matching function for call to 'Derived::Derived(int, std::string)'
}