Need help in understanding the sequence of event

Reference: http://www.cplusplus.com/doc/tutorial/inheritance/ -> What is inherited from the base class?

The code below is from the example from the above link. The output is as below:
Mother: no parameters
Daughter: int parameter

Mother: int parameter
Son: int parameter


Shouldn't the output be just
Daughter: int parameter
Son: int parameter
?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// constructors and derived classes
#include <iostream>
using namespace std;

class Mother {
  public:
    Mother ()
      { cout << "Mother: no parameters\n"; }
    Mother (int a)
      { cout << "Mother: int parameter\n"; }
};

class Daughter : public Mother {
  public:
    Daughter (int a)
      { cout << "Daughter: int parameter\n\n"; }
};

class Son : public Mother {
  public:
    Son (int a) : Mother (a)
      { cout << "Son: int parameter\n\n"; }
};

int main () {
  Daughter kelly(0);
  Son bud(0);
  
  return 0;
}
Base class constructors are always called by the derived classes.

On line 15, Daughter does not call any particular constructor, so Mother's default constructor is called by default.

On line 21, Son specifically calls Mother's int constructor.
Topic archived. No new replies allowed.