| Constructors and single inheritance. | Lecture 4 - slide 2 : 24 Program 1 |
// Single inheritance - warming up.
// 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
}