-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinterfaces_une.cpp
56 lines (47 loc) · 1.14 KB
/
interfaces_une.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
using namespace std;
// Interface
class Decorator {
public:
Decorator(double angle) : angle(angle) {}
virtual ~Decorator() {}
virtual void whatever() = 0;
protected:
double angle;
};
// Another Interface
template<class T>
class Complex {
public:
Complex(T *real, T *image)
: real(real), image(image) {}
~Complex() { delete real, image; }
virtual void echoComplex() = 0;
protected:
T *real, *image;
};
// IntComplex Implements both interfaces
//
class IntComplex : public Complex<int>, Decorator {
public:
IntComplex(int *real, int *image, int angle)
: Complex<int>(real, image), Decorator(angle)
{}
void whatever() override {
cout << "Decorating complex number with an angle of "
<< Decorator::angle << endl;
}
void echoComplex() override {
cout << " Y = " << *this->real << " + " << *this->image << "*J\n";
}
};
int main() {
int *real = new int(3);
int *image = new int(4);
IntComplex *c1 = new IntComplex(real, image, 10);
c1->whatever();
c1->echoComplex();
delete real, image, c1;
return 0;
}