-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
33 lines (27 loc) · 804 Bytes
/
main.cpp
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
31
32
33
#include <cstdlib>
#include <iostream>
/* When a class inherits from multiple base classes, its constructor might have to call
the constructors of the base classes. This example illustrates how to do this using
a MIL (member initialization list). */
class base1 {
public:
int x;
base1(int val) { x = val; } // Constructor has a parameter x.
};
class base2 {
public:
int y;
base2(int val) { y = val; } // Constructor has a parameter y.
};
class derived : public base1, public base2 {
public:
int z;
// Constructor calls base constructors via MIL.
derived(int valx, int valy, int valz) : base1(valx), base2(valy) { z = valz; }
};
int main(int argc, char* argv[])
{
derived d(1, 2, 3);
std::cout << d.x << d.y << d.z << std::endl;
return EXIT_SUCCESS;
}