Back to slide -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'          constructor-inh/single-1-cpp11.cc - Constructors and single inheritance - C++11 initialization syntax.Lecture 5 - slide 4 : 40
Program 1

// Single inheritance - warming up - C++11 variant.
// Illustrates how a Base constructor is used in the Derived constructors member initializer.

#include <iostream>
#include <string>

using namespace std;

class Base{
public:
  int i;
  string s;

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

class Derived: public Base{
public:
  double d;

  Derived(double d, int i, string s): Base{i+1, s+s}, d{d}{
  }
};

int main(){
  Base b1{1, "AP"};
  Derived d1{5.0, 1, "AP"};

  cout << b1.i << endl;            // 1
  cout << b1.s << endl << endl;    // AP

  cout << d1.d << endl;            // 5
  cout << d1.i << endl;            // 2
  cout << d1.s << endl;            // APAP

}