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
34
35
36
37
| class PoweredDevice { public : PoweredDevice( int nPower) { cout << "PoweredDevice: " << nPower << endl; } }; class Scanner: public PoweredDevice { public : Scanner( int nScanner, int nPower) : PoweredDevice(nPower) { cout << "Scanner: " << nScanner << endl; } }; class Printer: public PoweredDevice { public : Printer( int nPrinter, int nPower) : PoweredDevice(nPower) { cout << "Printer: " << nPrinter << endl; } }; class Copier: public Scanner, public Printer { public : Copier( int nScanner, int nPrinter, int nPower) : Scanner(nScanner, nPower), Printer(nPrinter, nPower) { } }; |
1
2
3
4
| int main() { Copier cCopier(1, 2, 3); } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| class PoweredDevice { }; class Scanner: virtual public PoweredDevice { }; class Printer: virtual public PoweredDevice { }; class Copier: public Scanner, public Printer { }; |
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
34
35
36
37
| class PoweredDevice { public : PoweredDevice( int nPower) { cout << "PoweredDevice: " << nPower << endl; } }; class Scanner: virtual public PoweredDevice { public : Scanner( int nScanner, int nPower) : PoweredDevice(nPower) { cout << "Scanner: " << nScanner << endl; } }; class Printer: virtual public PoweredDevice { public : Printer( int nPrinter, int nPower) : PoweredDevice(nPower) { cout << "Printer: " << nPrinter << endl; } }; class Copier: public Scanner, public Printer { public : Copier( int nScanner, int nPrinter, int nPower) : Scanner(nScanner, nPower), Printer(nPrinter, nPower), PoweredDevice(nPower) { } }; |
1
2
3
4
| int main() { Copier cCopier(1, 2, 3); } |
0 comments: