File tree 1 file changed +56
-0
lines changed
1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < string>
3
+
4
+ using namespace std ;
5
+
6
+ // Interface
7
+ class Decorator {
8
+ public:
9
+ Decorator (double angle) : angle(angle) {}
10
+ virtual ~Decorator () {}
11
+ virtual void whatever () = 0;
12
+ protected:
13
+ double angle;
14
+ };
15
+
16
+ // Another Interface
17
+ template <class T >
18
+ class Complex {
19
+ public:
20
+ Complex (T *real, T *image)
21
+ : real(real), image(image) {}
22
+ ~Complex () { delete real, image; }
23
+ virtual void echoComplex () = 0;
24
+ protected:
25
+ T *real, *image;
26
+ };
27
+
28
+ // IntComplex Implements both interfaces
29
+ //
30
+ class IntComplex : public Complex <int >, Decorator {
31
+ public:
32
+ IntComplex (int *real, int *image, int angle)
33
+ : Complex<int >(real, image), Decorator(angle)
34
+ {}
35
+ void whatever () override {
36
+ cout << " Decorating complex number with an angle of "
37
+ << Decorator::angle << endl;
38
+ }
39
+ void echoComplex () override {
40
+ cout << " Y = " << *this ->real << " + " << *this ->image << " *J\n " ;
41
+ }
42
+ };
43
+
44
+
45
+ int main () {
46
+
47
+ int *real = new int (3 );
48
+ int *image = new int (4 );
49
+ IntComplex *c1 = new IntComplex (real, image, 10 );
50
+ c1->whatever ();
51
+ c1->echoComplex ();
52
+
53
+ delete real, image, c1;
54
+
55
+ return 0 ;
56
+ }
You can’t perform that action at this time.
0 commit comments