File tree Expand file tree Collapse file tree 2 files changed +89
-1
lines changed Expand file tree Collapse file tree 2 files changed +89
-1
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ set(CMAKE_CXX_STANDARD 20)
23
23
#add_executable(isp_door ISP/isp_door_example.cpp)
24
24
#add_executable(isp_door_better ISP/isp_door_example_better.cpp)
25
25
#add_executable(isp_door_better2 ISP/isp_door_example_better2.cpp)
26
- add_executable (isp_device ISP/isp_device_example.cpp )
26
+ #add_executable(isp_device ISP/isp_device_example.cpp)
27
+ add_executable (isp_device_better ISP/isp_device_example_better.cpp )
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/19/21.
3
+ //
4
+
5
+ #include < iostream>
6
+ #include < stdexcept>
7
+
8
+ // Interfaces
9
+ class Printer
10
+ {
11
+
12
+ public:
13
+ virtual ~Printer () = default ;
14
+ virtual void print () = 0;
15
+ };
16
+
17
+ class Scanner
18
+ {
19
+ public:
20
+ virtual ~Scanner () = default ;
21
+ virtual void scan () = 0;
22
+ };
23
+
24
+ class Fax
25
+ {
26
+ public:
27
+ virtual ~Fax () = default ;
28
+ virtual void fax () = 0;
29
+ };
30
+
31
+
32
+ class AdvancedPrinter : public Printer , public Scanner , public Fax
33
+ {
34
+ public:
35
+ void print ()
36
+ {
37
+ std::cout << " Printing...\n " ;
38
+ }
39
+
40
+ void scan ()
41
+ {
42
+ std::cout << " Scanning...\n " ;
43
+ }
44
+
45
+ void fax ()
46
+ {
47
+ std::cout << " Faxing...\n " ;
48
+ }
49
+ };
50
+
51
+ class SimplePrinter : public Printer
52
+ {
53
+ public:
54
+ void print ()
55
+ {
56
+ std::cout << " Printing...\n " ;
57
+ }
58
+ };
59
+
60
+ // clients
61
+ void printUsers (Printer &printer)
62
+ {
63
+ printer.print ();
64
+ }
65
+
66
+ void scanUsers (Scanner &scanner)
67
+ {
68
+ scanner.scan ();
69
+ }
70
+
71
+ void faxUsers (Fax &fax)
72
+ {
73
+ fax.fax ();
74
+ }
75
+
76
+ int main ()
77
+ {
78
+ AdvancedPrinter advancedPrinter;
79
+ SimplePrinter simplePrinter;
80
+
81
+ printUsers (advancedPrinter);
82
+ scanUsers (advancedPrinter);
83
+ faxUsers (advancedPrinter);
84
+ // scanUsers(simplePrinter); // won't compile
85
+
86
+ return 0 ;
87
+ }
You can’t perform that action at this time.
0 commit comments